[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),
|
: _game_state(game_state), _should_close(false), _command_history_index(0),
|
||||||
_scroll_offset(0), _prompt(""), _pending_action({ActionType::NONE}),
|
_scroll_offset(0), _prompt(""), _pending_action({ActionType::NONE}),
|
||||||
_session_id(0) {
|
_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) {}
|
Terminal::~Terminal(void) {}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
Editor::Editor(void)
|
Editor::Editor(void)
|
||||||
: _should_close(false), _pending_action({ActionType::NONE}),
|
: _should_close(false), _pending_action({ActionType::NONE}),
|
||||||
_filename("untitled.txt") {
|
_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 = std::make_unique<MenuBar>(25);
|
||||||
_menu_bar->add_menu("File");
|
_menu_bar->add_menu("File");
|
||||||
_menu_bar->add_menu_item("File", "Save", [this]() {
|
_menu_bar->add_menu_item("File", "Save", [this]() {
|
||||||
@ -19,7 +19,7 @@ Editor::Editor(void)
|
|||||||
Editor::Editor(const std::string& filename)
|
Editor::Editor(const std::string& filename)
|
||||||
: _should_close(false), _pending_action({ActionType::NONE}),
|
: _should_close(false), _pending_action({ActionType::NONE}),
|
||||||
_filename(filename) {
|
_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 = std::make_unique<MenuBar>(25);
|
||||||
_menu_bar->add_menu("File");
|
_menu_bar->add_menu("File");
|
||||||
_menu_bar->add_menu_item("File", "Save", [this]() {
|
_menu_bar->add_menu_item("File", "Save", [this]() {
|
||||||
|
|||||||
@ -7,11 +7,13 @@
|
|||||||
#include "ui/text_buffer.h"
|
#include "ui/text_buffer.h"
|
||||||
#include "ui/ui_renderer.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),
|
_buffer(buffer),
|
||||||
_scroll_offset(0),
|
_scroll_offset(0),
|
||||||
_handle_ret(handle_ret),
|
_handle_ret(handle_ret),
|
||||||
_show_line_numbers(show_line_numbers) {
|
_show_line_numbers(show_line_numbers),
|
||||||
|
_syntax_highlighting(syntax_highlighting) {
|
||||||
|
|
||||||
_lua_keywords = {
|
_lua_keywords = {
|
||||||
"and", "break", "do", "else", "elseif", "end", "false", "for",
|
"and", "break", "do", "else", "elseif", "end", "false", "for",
|
||||||
@ -180,18 +182,22 @@ void TextView::render_text_content(UIRenderer* ui_renderer, const SyntaxTheme& t
|
|||||||
}
|
}
|
||||||
|
|
||||||
float current_x = x+padding + gutter_width;
|
float current_x = x+padding + gutter_width;
|
||||||
std::vector<Token> tokens = _tokenize_line(_buffer->get_line(i));
|
if(_syntax_highlighting) {
|
||||||
for(const auto& token : tokens) {
|
std::vector<Token> tokens = _tokenize_line(_buffer->get_line(i));
|
||||||
Color color = theme.normal;
|
for(const auto& token : tokens) {
|
||||||
switch(token.type) {
|
Color color = theme.normal;
|
||||||
case TokenType::KEYWORD: color = theme.keyword; break;
|
switch(token.type) {
|
||||||
case TokenType::STRING: color = theme.string; break;
|
case TokenType::KEYWORD: color = theme.keyword; break;
|
||||||
case TokenType::NUMBER: color = theme.number; break;
|
case TokenType::STRING: color = theme.string; break;
|
||||||
case TokenType::COMMENT: color = theme.comment; break;
|
case TokenType::NUMBER: color = theme.number; break;
|
||||||
default: break;
|
case TokenType::COMMENT: color = theme.comment; break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
ui_renderer->render_text(token.text.c_str(), current_x, current_y+18, color);
|
} else {
|
||||||
current_x += ui_renderer->get_text_renderer()->get_text_width(token.text.c_str(), 1.0f);
|
ui_renderer->render_text(_buffer->get_line(i).c_str(), current_x, current_y+18, theme.normal);
|
||||||
}
|
}
|
||||||
current_y += line_height;
|
current_y += line_height;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ struct Token {
|
|||||||
|
|
||||||
class TextView {
|
class TextView {
|
||||||
public:
|
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);
|
~TextView(void);
|
||||||
|
|
||||||
bool handle_event(SDL_Event* event);
|
bool handle_event(SDL_Event* event);
|
||||||
@ -43,5 +43,6 @@ private:
|
|||||||
int _scroll_offset;
|
int _scroll_offset;
|
||||||
bool _handle_ret;
|
bool _handle_ret;
|
||||||
bool _show_line_numbers;
|
bool _show_line_numbers;
|
||||||
|
bool _syntax_highlighting;
|
||||||
std::unordered_set<std::string> _lua_keywords;
|
std::unordered_set<std::string> _lua_keywords;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user