Add custom background line colour to TextEdit and remove marked lines

This commit is contained in:
Paulb23 2020-09-10 21:25:00 +01:00
parent 1cc8cc96cb
commit 00e10a842f
13 changed files with 121 additions and 184 deletions

View file

@ -193,8 +193,6 @@
</theme_item>
<theme_item name="line_spacing" type="int" default="4">
</theme_item>
<theme_item name="mark_color" type="Color" default="Color( 1, 0.4, 0.4, 0.4 )">
</theme_item>
<theme_item name="normal" type="StyleBox">
</theme_item>
<theme_item name="outline_size" type="int" default="0">

View file

@ -167,6 +167,15 @@
Returns the text of a specific line.
</description>
</method>
<method name="get_line_background_color">
<return type="Color">
</return>
<argument index="0" name="line" type="int">
</argument>
<description>
Returns the current background color of the line. [code]Color(0, 0, 0, 0)[/code] is returned if no color is set.
</description>
</method>
<method name="get_line_count" qualifiers="const">
<return type="int">
</return>
@ -548,6 +557,17 @@
If [code]true[/code], hides the line of the specified index.
</description>
</method>
<method name="set_line_background_color">
<return type="void">
</return>
<argument index="0" name="line" type="int">
</argument>
<argument index="1" name="color" type="Color">
</argument>
<description>
Sets the current background color of the line. Set to [code]Color(0, 0, 0, 0)[/code] for no color.
</description>
</method>
<method name="set_line_gutter_clickable">
<return type="void">
</return>
@ -987,9 +1007,6 @@
<theme_item name="line_spacing" type="int" default="4">
Sets the spacing between the lines.
</theme_item>
<theme_item name="mark_color" type="Color" default="Color( 1, 0.4, 0.4, 0.4 )">
Sets the [Color] of marked text.
</theme_item>
<theme_item name="normal" type="StyleBox">
Sets the [StyleBox] of this [TextEdit].
</theme_item>

View file

@ -1474,6 +1474,34 @@ void CodeTextEditor::goto_error() {
}
}
void CodeTextEditor::_update_text_editor_theme() {
text_editor->add_theme_color_override("background_color", EDITOR_GET("text_editor/highlighting/background_color"));
text_editor->add_theme_color_override("completion_background_color", EDITOR_GET("text_editor/highlighting/completion_background_color"));
text_editor->add_theme_color_override("completion_selected_color", EDITOR_GET("text_editor/highlighting/completion_selected_color"));
text_editor->add_theme_color_override("completion_existing_color", EDITOR_GET("text_editor/highlighting/completion_existing_color"));
text_editor->add_theme_color_override("completion_scroll_color", EDITOR_GET("text_editor/highlighting/completion_scroll_color"));
text_editor->add_theme_color_override("completion_font_color", EDITOR_GET("text_editor/highlighting/completion_font_color"));
text_editor->add_theme_color_override("font_color", EDITOR_GET("text_editor/highlighting/text_color"));
text_editor->add_theme_color_override("line_number_color", EDITOR_GET("text_editor/highlighting/line_number_color"));
text_editor->add_theme_color_override("caret_color", EDITOR_GET("text_editor/highlighting/caret_color"));
text_editor->add_theme_color_override("caret_background_color", EDITOR_GET("text_editor/highlighting/caret_background_color"));
text_editor->add_theme_color_override("font_selected_color", EDITOR_GET("text_editor/highlighting/text_selected_color"));
text_editor->add_theme_color_override("selection_color", EDITOR_GET("text_editor/highlighting/selection_color"));
text_editor->add_theme_color_override("brace_mismatch_color", EDITOR_GET("text_editor/highlighting/brace_mismatch_color"));
text_editor->add_theme_color_override("current_line_color", EDITOR_GET("text_editor/highlighting/current_line_color"));
text_editor->add_theme_color_override("line_length_guideline_color", EDITOR_GET("text_editor/highlighting/line_length_guideline_color"));
text_editor->add_theme_color_override("word_highlighted_color", EDITOR_GET("text_editor/highlighting/word_highlighted_color"));
text_editor->add_theme_color_override("bookmark_color", EDITOR_GET("text_editor/highlighting/bookmark_color"));
text_editor->add_theme_color_override("breakpoint_color", EDITOR_GET("text_editor/highlighting/breakpoint_color"));
text_editor->add_theme_color_override("executing_line_color", EDITOR_GET("text_editor/highlighting/executing_line_color"));
text_editor->add_theme_color_override("code_folding_color", EDITOR_GET("text_editor/highlighting/code_folding_color"));
text_editor->add_theme_color_override("search_result_color", EDITOR_GET("text_editor/highlighting/search_result_color"));
text_editor->add_theme_color_override("search_result_border_color", EDITOR_GET("text_editor/highlighting/search_result_border_color"));
text_editor->add_theme_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 6));
emit_signal("load_theme_settings");
_load_theme_settings();
}
void CodeTextEditor::_update_font() {
text_editor->add_theme_font_override("font", get_theme_font("source", "EditorFonts"));
text_editor->add_theme_font_size_override("font_size", get_theme_font_size("source_size", "EditorFonts"));
@ -1497,6 +1525,7 @@ void CodeTextEditor::_update_font() {
}
void CodeTextEditor::_on_settings_change() {
_update_text_editor_theme();
_update_font();
font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size");
@ -1583,14 +1612,11 @@ void CodeTextEditor::_error_pressed(const Ref<InputEvent> &p_event) {
void CodeTextEditor::_notification(int p_what) {
switch (p_what) {
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
_load_theme_settings();
emit_signal("load_theme_settings");
} break;
case NOTIFICATION_THEME_CHANGED: {
if (toggle_scripts_button->is_visible()) {
update_toggle_scripts_button();
}
_update_text_editor_theme();
_update_font();
} break;
case NOTIFICATION_ENTER_TREE: {

View file

@ -161,6 +161,7 @@ class CodeTextEditor : public VBoxContainer {
void _on_settings_change();
void _update_text_editor_theme();
void _update_font();
void _complete_request();
Ref<Texture2D> _get_completion_icon(const ScriptCodeCompletionOption &p_option);

View file

@ -170,66 +170,25 @@ void ScriptTextEditor::_load_theme_settings() {
CodeEdit *text_edit = code_editor->get_text_editor();
text_edit->clear_keywords();
Color updated_marked_line_color = EDITOR_GET("text_editor/highlighting/mark_color");
Color updated_safe_line_number_color = EDITOR_GET("text_editor/highlighting/safe_line_number_color");
if (updated_safe_line_number_color != safe_line_number_color) {
bool safe_line_number_color_updated = updated_safe_line_number_color != safe_line_number_color;
bool marked_line_color_updated = updated_marked_line_color != marked_line_color;
if (safe_line_number_color_updated || marked_line_color_updated) {
safe_line_number_color = updated_safe_line_number_color;
for (int i = 0; i < text_edit->get_line_count(); i++) {
if (text_edit->get_line_gutter_item_color(i, line_number_gutter) != default_line_number_color) {
if (marked_line_color_updated && text_edit->get_line_background_color(i) == marked_line_color) {
text_edit->set_line_background_color(i, updated_marked_line_color);
}
if (safe_line_number_color_updated && text_edit->get_line_gutter_item_color(i, line_number_gutter) != default_line_number_color) {
text_edit->set_line_gutter_item_color(i, line_number_gutter, safe_line_number_color);
}
}
marked_line_color = updated_marked_line_color;
}
Color background_color = EDITOR_GET("text_editor/highlighting/background_color");
Color completion_background_color = EDITOR_GET("text_editor/highlighting/completion_background_color");
Color completion_selected_color = EDITOR_GET("text_editor/highlighting/completion_selected_color");
Color completion_existing_color = EDITOR_GET("text_editor/highlighting/completion_existing_color");
Color completion_scroll_color = EDITOR_GET("text_editor/highlighting/completion_scroll_color");
Color completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color");
Color text_color = EDITOR_GET("text_editor/highlighting/text_color");
Color line_number_color = EDITOR_GET("text_editor/highlighting/line_number_color");
Color caret_color = EDITOR_GET("text_editor/highlighting/caret_color");
Color caret_background_color = EDITOR_GET("text_editor/highlighting/caret_background_color");
Color text_selected_color = EDITOR_GET("text_editor/highlighting/text_selected_color");
Color selection_color = EDITOR_GET("text_editor/highlighting/selection_color");
Color brace_mismatch_color = EDITOR_GET("text_editor/highlighting/brace_mismatch_color");
Color current_line_color = EDITOR_GET("text_editor/highlighting/current_line_color");
Color line_length_guideline_color = EDITOR_GET("text_editor/highlighting/line_length_guideline_color");
Color word_highlighted_color = EDITOR_GET("text_editor/highlighting/word_highlighted_color");
Color mark_color = EDITOR_GET("text_editor/highlighting/mark_color");
Color bookmark_color = EDITOR_GET("text_editor/highlighting/bookmark_color");
Color breakpoint_color = EDITOR_GET("text_editor/highlighting/breakpoint_color");
Color executing_line_color = EDITOR_GET("text_editor/highlighting/executing_line_color");
Color code_folding_color = EDITOR_GET("text_editor/highlighting/code_folding_color");
Color search_result_color = EDITOR_GET("text_editor/highlighting/search_result_color");
Color search_result_border_color = EDITOR_GET("text_editor/highlighting/search_result_border_color");
text_edit->add_theme_color_override("background_color", background_color);
text_edit->add_theme_color_override("completion_background_color", completion_background_color);
text_edit->add_theme_color_override("completion_selected_color", completion_selected_color);
text_edit->add_theme_color_override("completion_existing_color", completion_existing_color);
text_edit->add_theme_color_override("completion_scroll_color", completion_scroll_color);
text_edit->add_theme_color_override("completion_font_color", completion_font_color);
text_edit->add_theme_color_override("font_color", text_color);
text_edit->add_theme_color_override("line_number_color", line_number_color);
text_edit->add_theme_color_override("caret_color", caret_color);
text_edit->add_theme_color_override("caret_background_color", caret_background_color);
text_edit->add_theme_color_override("font_selected_color", text_selected_color);
text_edit->add_theme_color_override("selection_color", selection_color);
text_edit->add_theme_color_override("brace_mismatch_color", brace_mismatch_color);
text_edit->add_theme_color_override("current_line_color", current_line_color);
text_edit->add_theme_color_override("line_length_guideline_color", line_length_guideline_color);
text_edit->add_theme_color_override("word_highlighted_color", word_highlighted_color);
text_edit->add_theme_color_override("bookmark_color", bookmark_color);
text_edit->add_theme_color_override("breakpoint_color", breakpoint_color);
text_edit->add_theme_color_override("executing_line_color", executing_line_color);
text_edit->add_theme_color_override("mark_color", mark_color);
text_edit->add_theme_color_override("code_folding_color", code_folding_color);
text_edit->add_theme_color_override("search_result_color", search_result_color);
text_edit->add_theme_color_override("search_result_border_color", search_result_border_color);
text_edit->add_theme_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 6));
theme_loaded = true;
if (!script.is_null()) {
_set_theme_for_script();
@ -546,7 +505,7 @@ void ScriptTextEditor::_validate_script() {
bool highlight_safe = EDITOR_DEF("text_editor/highlighting/highlight_type_safe_lines", true);
bool last_is_safe = false;
for (int i = 0; i < te->get_line_count(); i++) {
te->set_line_as_marked(i, line == i);
te->set_line_background_color(i, (line == i) ? marked_line_color : Color(0, 0, 0, 0));
if (highlight_safe) {
if (safe_lines.has(i + 1)) {
te->set_line_gutter_item_color(i, line_number_gutter, safe_line_number_color);

View file

@ -89,6 +89,8 @@ class ScriptTextEditor : public ScriptEditorBase {
Color default_line_number_color = Color(1, 1, 1);
Color safe_line_number_color = Color(1, 1, 1);
Color marked_line_color = Color(1, 1, 1);
PopupPanel *color_panel = nullptr;
ColorPicker *color_picker = nullptr;
Vector2 color_position;

View file

@ -83,53 +83,16 @@ void ShaderTextEditor::reload_text() {
}
void ShaderTextEditor::_load_theme_settings() {
Color background_color = EDITOR_GET("text_editor/highlighting/background_color");
Color completion_background_color = EDITOR_GET("text_editor/highlighting/completion_background_color");
Color completion_selected_color = EDITOR_GET("text_editor/highlighting/completion_selected_color");
Color completion_existing_color = EDITOR_GET("text_editor/highlighting/completion_existing_color");
Color completion_scroll_color = EDITOR_GET("text_editor/highlighting/completion_scroll_color");
Color completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color");
Color text_color = EDITOR_GET("text_editor/highlighting/text_color");
Color line_number_color = EDITOR_GET("text_editor/highlighting/line_number_color");
Color caret_color = EDITOR_GET("text_editor/highlighting/caret_color");
Color caret_background_color = EDITOR_GET("text_editor/highlighting/caret_background_color");
Color text_selected_color = EDITOR_GET("text_editor/highlighting/text_selected_color");
Color selection_color = EDITOR_GET("text_editor/highlighting/selection_color");
Color brace_mismatch_color = EDITOR_GET("text_editor/highlighting/brace_mismatch_color");
Color current_line_color = EDITOR_GET("text_editor/highlighting/current_line_color");
Color line_length_guideline_color = EDITOR_GET("text_editor/highlighting/line_length_guideline_color");
Color word_highlighted_color = EDITOR_GET("text_editor/highlighting/word_highlighted_color");
Color mark_color = EDITOR_GET("text_editor/highlighting/mark_color");
Color bookmark_color = EDITOR_GET("text_editor/highlighting/bookmark_color");
Color breakpoint_color = EDITOR_GET("text_editor/highlighting/breakpoint_color");
Color executing_line_color = EDITOR_GET("text_editor/highlighting/executing_line_color");
Color code_folding_color = EDITOR_GET("text_editor/highlighting/code_folding_color");
Color search_result_color = EDITOR_GET("text_editor/highlighting/search_result_color");
Color search_result_border_color = EDITOR_GET("text_editor/highlighting/search_result_border_color");
get_text_editor()->add_theme_color_override("background_color", background_color);
get_text_editor()->add_theme_color_override("completion_background_color", completion_background_color);
get_text_editor()->add_theme_color_override("completion_selected_color", completion_selected_color);
get_text_editor()->add_theme_color_override("completion_existing_color", completion_existing_color);
get_text_editor()->add_theme_color_override("completion_scroll_color", completion_scroll_color);
get_text_editor()->add_theme_color_override("completion_font_color", completion_font_color);
get_text_editor()->add_theme_color_override("font_color", text_color);
get_text_editor()->add_theme_color_override("line_number_color", line_number_color);
get_text_editor()->add_theme_color_override("caret_color", caret_color);
get_text_editor()->add_theme_color_override("caret_background_color", caret_background_color);
get_text_editor()->add_theme_color_override("font_selected_color", text_selected_color);
get_text_editor()->add_theme_color_override("selection_color", selection_color);
get_text_editor()->add_theme_color_override("brace_mismatch_color", brace_mismatch_color);
get_text_editor()->add_theme_color_override("current_line_color", current_line_color);
get_text_editor()->add_theme_color_override("line_length_guideline_color", line_length_guideline_color);
get_text_editor()->add_theme_color_override("word_highlighted_color", word_highlighted_color);
get_text_editor()->add_theme_color_override("mark_color", mark_color);
get_text_editor()->add_theme_color_override("bookmark_color", bookmark_color);
get_text_editor()->add_theme_color_override("breakpoint_color", breakpoint_color);
get_text_editor()->add_theme_color_override("executing_line_color", executing_line_color);
get_text_editor()->add_theme_color_override("code_folding_color", code_folding_color);
get_text_editor()->add_theme_color_override("search_result_color", search_result_color);
get_text_editor()->add_theme_color_override("search_result_border_color", search_result_border_color);
CodeEdit *text_editor = get_text_editor();
Color updated_marked_line_color = EDITOR_GET("text_editor/highlighting/mark_color");
if (updated_marked_line_color != marked_line_color) {
for (int i = 0; i < text_editor->get_line_count(); i++) {
if (text_editor->get_line_background_color(i) == marked_line_color) {
text_editor->set_line_background_color(i, updated_marked_line_color);
}
}
marked_line_color = updated_marked_line_color;
}
syntax_highlighter->set_number_color(EDITOR_GET("text_editor/highlighting/number_color"));
syntax_highlighter->set_symbol_color(EDITOR_GET("text_editor/highlighting/symbol_color"));
@ -231,13 +194,13 @@ void ShaderTextEditor::_validate_script() {
set_error(error_text);
set_error_pos(sl.get_error_line() - 1, 0);
for (int i = 0; i < get_text_editor()->get_line_count(); i++) {
get_text_editor()->set_line_as_marked(i, false);
get_text_editor()->set_line_background_color(i, Color(0, 0, 0, 0));
}
get_text_editor()->set_line_as_marked(sl.get_error_line() - 1, true);
get_text_editor()->set_line_background_color(sl.get_error_line() - 1, marked_line_color);
} else {
for (int i = 0; i < get_text_editor()->get_line_count(); i++) {
get_text_editor()->set_line_as_marked(i, false);
get_text_editor()->set_line_background_color(i, Color(0, 0, 0, 0));
}
set_error("");
}

View file

@ -44,6 +44,8 @@
class ShaderTextEditor : public CodeTextEditor {
GDCLASS(ShaderTextEditor, CodeTextEditor);
Color marked_line_color = Color(1, 1, 1);
Ref<CodeHighlighter> syntax_highlighter;
Ref<Shader> shader;

View file

@ -59,58 +59,7 @@ void TextEditor::_change_syntax_highlighter(int p_idx) {
}
void TextEditor::_load_theme_settings() {
CodeEdit *text_edit = code_editor->get_text_editor();
text_edit->get_syntax_highlighter()->update_cache();
Color background_color = EDITOR_GET("text_editor/highlighting/background_color");
Color completion_background_color = EDITOR_GET("text_editor/highlighting/completion_background_color");
Color completion_selected_color = EDITOR_GET("text_editor/highlighting/completion_selected_color");
Color completion_existing_color = EDITOR_GET("text_editor/highlighting/completion_existing_color");
Color completion_scroll_color = EDITOR_GET("text_editor/highlighting/completion_scroll_color");
Color completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color");
Color text_color = EDITOR_GET("text_editor/highlighting/text_color");
Color line_number_color = EDITOR_GET("text_editor/highlighting/line_number_color");
Color caret_color = EDITOR_GET("text_editor/highlighting/caret_color");
Color caret_background_color = EDITOR_GET("text_editor/highlighting/caret_background_color");
Color text_selected_color = EDITOR_GET("text_editor/highlighting/text_selected_color");
Color selection_color = EDITOR_GET("text_editor/highlighting/selection_color");
Color brace_mismatch_color = EDITOR_GET("text_editor/highlighting/brace_mismatch_color");
Color current_line_color = EDITOR_GET("text_editor/highlighting/current_line_color");
Color line_length_guideline_color = EDITOR_GET("text_editor/highlighting/line_length_guideline_color");
Color word_highlighted_color = EDITOR_GET("text_editor/highlighting/word_highlighted_color");
Color mark_color = EDITOR_GET("text_editor/highlighting/mark_color");
Color bookmark_color = EDITOR_GET("text_editor/highlighting/bookmark_color");
Color breakpoint_color = EDITOR_GET("text_editor/highlighting/breakpoint_color");
Color executing_line_color = EDITOR_GET("text_editor/highlighting/executing_line_color");
Color code_folding_color = EDITOR_GET("text_editor/highlighting/code_folding_color");
Color search_result_color = EDITOR_GET("text_editor/highlighting/search_result_color");
Color search_result_border_color = EDITOR_GET("text_editor/highlighting/search_result_border_color");
text_edit->add_theme_color_override("background_color", background_color);
text_edit->add_theme_color_override("completion_background_color", completion_background_color);
text_edit->add_theme_color_override("completion_selected_color", completion_selected_color);
text_edit->add_theme_color_override("completion_existing_color", completion_existing_color);
text_edit->add_theme_color_override("completion_scroll_color", completion_scroll_color);
text_edit->add_theme_color_override("completion_font_color", completion_font_color);
text_edit->add_theme_color_override("font_color", text_color);
text_edit->add_theme_color_override("line_number_color", line_number_color);
text_edit->add_theme_color_override("caret_color", caret_color);
text_edit->add_theme_color_override("caret_background_color", caret_background_color);
text_edit->add_theme_color_override("font_selected_color", text_selected_color);
text_edit->add_theme_color_override("selection_color", selection_color);
text_edit->add_theme_color_override("brace_mismatch_color", brace_mismatch_color);
text_edit->add_theme_color_override("current_line_color", current_line_color);
text_edit->add_theme_color_override("line_length_guideline_color", line_length_guideline_color);
text_edit->add_theme_color_override("word_highlighted_color", word_highlighted_color);
text_edit->add_theme_color_override("breakpoint_color", breakpoint_color);
text_edit->add_theme_color_override("executing_line_color", executing_line_color);
text_edit->add_theme_color_override("mark_color", mark_color);
text_edit->add_theme_color_override("bookmark_color", bookmark_color);
text_edit->add_theme_color_override("code_folding_color", code_folding_color);
text_edit->add_theme_color_override("search_result_color", search_result_color);
text_edit->add_theme_color_override("search_result_border_color", search_result_border_color);
text_edit->add_theme_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 6));
code_editor->get_text_editor()->get_syntax_highlighter()->update_cache();
}
String TextEditor::get_name() {

View file

@ -3429,10 +3429,11 @@ void VisualShaderEditor::_update_preview() {
Error err = sl.compile(code, ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(visual_shader->get_mode())), ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(visual_shader->get_mode())), ShaderLanguage::VaryingFunctionNames(), ShaderTypes::get_singleton()->get_types(), _get_global_variable_type);
for (int i = 0; i < preview_text->get_line_count(); i++) {
preview_text->set_line_as_marked(i, false);
preview_text->set_line_background_color(i, Color(0, 0, 0, 0));
}
if (err != OK) {
preview_text->set_line_as_marked(sl.get_error_line() - 1, true);
Color error_line_color = EDITOR_GET("text_editor/highlighting/mark_color");
preview_text->set_line_background_color(sl.get_error_line() - 1, error_line_color);
error_text->set_visible(true);
String text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text();

View file

@ -253,7 +253,6 @@ void TextEdit::Text::set(int p_line, const String &p_text, const Vector<Vector2i
void TextEdit::Text::insert(int p_at, const String &p_text, const Vector<Vector2i> &p_bidi_override) {
Line line;
line.gutters.resize(gutter_count);
line.marked = false;
line.hidden = false;
line.data = p_text;
line.bidi_override = p_bidi_override;
@ -867,6 +866,8 @@ void TextEdit::_notification(int p_what) {
Dictionary color_map = _get_line_syntax_highlighting(minimap_line);
Color line_background_color = text.get_line_background_color(minimap_line);
line_background_color.a *= 0.6;
Color current_color = cache.font_color;
if (readonly) {
current_color = cache.font_readonly_color;
@ -901,6 +902,12 @@ void TextEdit::_notification(int p_what) {
} else {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, cache.minimap_width, 2), cache.current_line_color);
}
} else if (line_background_color != Color(0, 0, 0, 0)) {
if (rtl) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - (xmargin_end + 2) - cache.minimap_width, i * 3, cache.minimap_width, 2), line_background_color);
} else {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2((xmargin_end + 2), i * 3, cache.minimap_width, 2), line_background_color);
}
}
Color previous_color;
@ -1048,11 +1055,11 @@ void TextEdit::_notification(int p_what) {
break;
}
if (text.is_marked(line)) {
if (text.get_line_background_color(line) != Color(0, 0, 0, 0)) {
if (rtl) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - ofs_x - xmargin_end, ofs_y, xmargin_end - xmargin_beg, row_height), cache.mark_color);
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - ofs_x - xmargin_end, ofs_y, xmargin_end - xmargin_beg, row_height), text.get_line_background_color(line));
} else {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, row_height), cache.mark_color);
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - xmargin_beg, row_height), text.get_line_background_color(line));
}
}
@ -4789,7 +4796,6 @@ void TextEdit::_update_caches() {
cache.font_selected_color = get_theme_color("font_selected_color");
cache.font_readonly_color = get_theme_color("font_readonly_color");
cache.selection_color = get_theme_color("selection_color");
cache.mark_color = get_theme_color("mark_color");
cache.current_line_color = get_theme_color("current_line_color");
cache.line_length_guideline_color = get_theme_color("line_length_guideline_color");
cache.code_folding_color = get_theme_color("code_folding_color");
@ -5019,6 +5025,18 @@ bool TextEdit::is_line_gutter_clickable(int p_line, int p_gutter) const {
return text.is_line_gutter_clickable(p_line, p_gutter);
}
// Line style
void TextEdit::set_line_background_color(int p_line, const Color &p_color) {
ERR_FAIL_INDEX(p_line, text.size());
text.set_line_background_color(p_line, p_color);
update();
}
Color TextEdit::get_line_background_color(int p_line) {
ERR_FAIL_INDEX_V(p_line, text.size(), Color());
return text.get_line_background_color(p_line);
}
void TextEdit::add_keyword(const String &p_keyword) {
keywords.insert(p_keyword);
}
@ -5437,12 +5455,6 @@ void TextEdit::_text_changed_emit() {
text_changed_dirty = false;
}
void TextEdit::set_line_as_marked(int p_line, bool p_marked) {
ERR_FAIL_INDEX(p_line, text.size());
text.set_marked(p_line, p_marked);
update();
}
void TextEdit::set_line_as_hidden(int p_line, bool p_hidden) {
ERR_FAIL_INDEX(p_line, text.size());
if (is_hiding_enabled() || !p_hidden) {
@ -6980,6 +6992,10 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_line_gutter_clickable", "line", "gutter", "clickable"), &TextEdit::set_line_gutter_clickable);
ClassDB::bind_method(D_METHOD("is_line_gutter_clickable", "line", "gutter"), &TextEdit::is_line_gutter_clickable);
// Line style
ClassDB::bind_method(D_METHOD("set_line_background_color", "line", "color"), &TextEdit::set_line_background_color);
ClassDB::bind_method(D_METHOD("get_line_background_color", "line"), &TextEdit::get_line_background_color);
ClassDB::bind_method(D_METHOD("set_highlight_current_line", "enabled"), &TextEdit::set_highlight_current_line);
ClassDB::bind_method(D_METHOD("is_highlight_current_line_enabled"), &TextEdit::is_highlight_current_line_enabled);

View file

@ -92,7 +92,7 @@ private:
Vector<Vector2i> bidi_override;
Ref<TextParagraph> data_buf;
bool marked = false;
Color background_color = Color(0, 0, 0, 0);
bool hidden = false;
Line() {
@ -129,12 +129,11 @@ private:
void set_width(float p_width);
int get_line_wrap_amount(int p_line) const;
Vector<Vector2i> get_line_wrap_ranges(int p_line) const;
const Ref<TextParagraph> get_line_data(int p_line) const;
void set(int p_line, const String &p_text, const Vector<Vector2i> &p_bidi_override);
void set_marked(int p_line, bool p_marked) { text.write[p_line].marked = p_marked; }
bool is_marked(int p_line) const { return text[p_line].marked; }
void set_hidden(int p_line, bool p_hidden) { text.write[p_line].hidden = p_hidden; }
bool is_hidden(int p_line) const { return text[p_line].hidden; }
void insert(int p_at, const String &p_text, const Vector<Vector2i> &p_bidi_override);
@ -167,6 +166,10 @@ private:
void set_line_gutter_clickable(int p_line, int p_gutter, bool p_clickable) { text.write[p_line].gutters.write[p_gutter].clickable = p_clickable; }
bool is_line_gutter_clickable(int p_line, int p_gutter) const { return text[p_line].gutters[p_gutter].clickable; }
/* Line style. */
void set_line_background_color(int p_line, const Color &p_color) { text.write[p_line].background_color = p_color; }
const Color get_line_background_color(int p_line) const { return text[p_line].background_color; }
};
struct Cursor {
@ -484,7 +487,6 @@ protected:
Color font_selected_color;
Color font_readonly_color;
Color selection_color;
Color mark_color;
Color code_folding_color;
Color current_line_color;
Color line_length_guideline_color;
@ -561,6 +563,10 @@ public:
void set_line_gutter_clickable(int p_line, int p_gutter, bool p_clickable);
bool is_line_gutter_clickable(int p_line, int p_gutter) const;
// Line style
void set_line_background_color(int p_line, const Color &p_color);
Color get_line_background_color(int p_line);
enum MenuItems {
MENU_CUT,
MENU_COPY,
@ -637,7 +643,6 @@ public:
void insert_text_at_cursor(const String &p_text);
void insert_at(const String &p_text, int at);
int get_line_count() const;
void set_line_as_marked(int p_line, bool p_marked);
void set_line_as_hidden(int p_line, bool p_hidden);
bool is_line_hidden(int p_line) const;

View file

@ -451,7 +451,6 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_color("font_readonly_color", "TextEdit", Color(control_font_color.r, control_font_color.g, control_font_color.b, 0.5f));
theme->set_color("font_outline_color", "TextEdit", Color(1, 1, 1));
theme->set_color("selection_color", "TextEdit", control_selection_color);
theme->set_color("mark_color", "TextEdit", Color(1.0, 0.4, 0.4, 0.4));
theme->set_color("code_folding_color", "TextEdit", Color(0.8, 0.8, 0.8, 0.8));
theme->set_color("current_line_color", "TextEdit", Color(0.25, 0.25, 0.26, 0.8));
theme->set_color("caret_color", "TextEdit", control_font_color);
@ -494,7 +493,6 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_color("font_readonly_color", "CodeEdit", Color(control_font_color.r, control_font_color.g, control_font_color.b, 0.5f));
theme->set_color("font_outline_color", "CodeEdit", Color(1, 1, 1));
theme->set_color("selection_color", "CodeEdit", control_selection_color);
theme->set_color("mark_color", "CodeEdit", Color(1.0, 0.4, 0.4, 0.4));
theme->set_color("bookmark_color", "CodeEdit", Color(0.5, 0.64, 1, 0.8));
theme->set_color("breakpoint_color", "CodeEdit", Color(0.9, 0.29, 0.3));
theme->set_color("executing_line_color", "CodeEdit", Color(0.98, 0.89, 0.27));