[Fix] Only apply tokenization to editor.
This commit is contained in:
		
							parent
							
								
									420b570902
								
							
						
					
					
						commit
						6a5515e276
					
				@ -15,7 +15,7 @@ Terminal::Terminal(GameState* game_state)
 | 
			
		||||
    : _game_state(game_state), _should_close(false), _command_history_index(0),
 | 
			
		||||
      _scroll_offset(0), _prompt(""), _pending_action({ActionType::NONE}),
 | 
			
		||||
      _session_id(0) {
 | 
			
		||||
  _input_view = std::make_unique<TextView>(&_input_buffer, false, false);
 | 
			
		||||
  _input_view = std::make_unique<TextView>(&_input_buffer, false, false, false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Terminal::~Terminal(void) {}
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,7 @@
 | 
			
		||||
Editor::Editor(void)
 | 
			
		||||
    : _should_close(false), _pending_action({ActionType::NONE}),
 | 
			
		||||
      _filename("untitled.txt") {
 | 
			
		||||
  _view = std::make_unique<TextView>(&_buffer, true, true);
 | 
			
		||||
  _view = std::make_unique<TextView>(&_buffer, true, true, true);
 | 
			
		||||
  _menu_bar = std::make_unique<MenuBar>(25);
 | 
			
		||||
  _menu_bar->add_menu("File");
 | 
			
		||||
  _menu_bar->add_menu_item("File", "Save", [this]() {
 | 
			
		||||
@ -19,7 +19,7 @@ Editor::Editor(void)
 | 
			
		||||
Editor::Editor(const std::string& filename)
 | 
			
		||||
    : _should_close(false), _pending_action({ActionType::NONE}),
 | 
			
		||||
      _filename(filename) {
 | 
			
		||||
  _view = std::make_unique<TextView>(&_buffer, true, true);
 | 
			
		||||
  _view = std::make_unique<TextView>(&_buffer, true, true, true);
 | 
			
		||||
  _menu_bar = std::make_unique<MenuBar>(25);
 | 
			
		||||
  _menu_bar->add_menu("File");
 | 
			
		||||
  _menu_bar->add_menu_item("File", "Save", [this]() {
 | 
			
		||||
 | 
			
		||||
@ -7,11 +7,13 @@
 | 
			
		||||
#include "ui/text_buffer.h"
 | 
			
		||||
#include "ui/ui_renderer.h"
 | 
			
		||||
 | 
			
		||||
TextView::TextView(TextBuffer* buffer, bool handle_ret, bool show_line_numbers) :
 | 
			
		||||
TextView::TextView(TextBuffer* buffer, bool handle_ret, bool show_line_numbers,
 | 
			
		||||
                   bool syntax_highlighting) :
 | 
			
		||||
      _buffer(buffer),
 | 
			
		||||
      _scroll_offset(0),
 | 
			
		||||
      _handle_ret(handle_ret),
 | 
			
		||||
      _show_line_numbers(show_line_numbers) {
 | 
			
		||||
      _show_line_numbers(show_line_numbers),
 | 
			
		||||
      _syntax_highlighting(syntax_highlighting) {
 | 
			
		||||
 | 
			
		||||
  _lua_keywords = {
 | 
			
		||||
    "and", "break", "do", "else", "elseif", "end", "false", "for",
 | 
			
		||||
@ -180,6 +182,7 @@ void TextView::render_text_content(UIRenderer* ui_renderer, const SyntaxTheme& t
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    float current_x = x+padding + gutter_width;
 | 
			
		||||
    if(_syntax_highlighting) {
 | 
			
		||||
      std::vector<Token> tokens = _tokenize_line(_buffer->get_line(i));
 | 
			
		||||
      for(const auto& token : tokens) {
 | 
			
		||||
        Color color = theme.normal;
 | 
			
		||||
@ -193,6 +196,9 @@ void TextView::render_text_content(UIRenderer* ui_renderer, const SyntaxTheme& t
 | 
			
		||||
        ui_renderer->render_text(token.text.c_str(), current_x, current_y+18, color);
 | 
			
		||||
        current_x += ui_renderer->get_text_renderer()->get_text_width(token.text.c_str(), 1.0f);
 | 
			
		||||
      } 
 | 
			
		||||
    } else {
 | 
			
		||||
      ui_renderer->render_text(_buffer->get_line(i).c_str(), current_x, current_y+18, theme.normal);
 | 
			
		||||
    }
 | 
			
		||||
    current_y += line_height;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -26,7 +26,7 @@ struct Token {
 | 
			
		||||
 | 
			
		||||
class TextView {
 | 
			
		||||
public:
 | 
			
		||||
  TextView(TextBuffer* buffer, bool handle_ret, bool show_line_numbers);
 | 
			
		||||
  TextView(TextBuffer* buffer, bool handle_ret, bool show_line_numbers, bool syntax_highlighting);
 | 
			
		||||
  ~TextView(void);
 | 
			
		||||
 | 
			
		||||
  bool handle_event(SDL_Event* event);
 | 
			
		||||
@ -43,5 +43,6 @@ private:
 | 
			
		||||
  int _scroll_offset;
 | 
			
		||||
  bool _handle_ret;
 | 
			
		||||
  bool _show_line_numbers;
 | 
			
		||||
  bool _syntax_highlighting;
 | 
			
		||||
  std::unordered_set<std::string> _lua_keywords;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user