Rename insert mode to overtype mode

This commit is contained in:
Paulb23 2021-07-09 13:40:05 +01:00
parent b700011314
commit b799e5583a
4 changed files with 38 additions and 22 deletions

View file

@ -391,6 +391,13 @@
Returns if the given line is wrapped.
</description>
</method>
<method name="is_overtype_mode_enabled" qualifiers="const">
<return type="bool">
</return>
<description>
Gets if the user is in overtype mode.
</description>
</method>
<method name="menu_option">
<return type="void" />
<argument index="0" name="option" type="int" />
@ -620,6 +627,15 @@
Sets OpenType feature [code]tag[/code]. More info: [url=https://docs.microsoft.com/en-us/typography/opentype/spec/featuretags]OpenType feature tags[/url].
</description>
</method>
<method name="set_overtype_mode_enabled">
<return type="void">
</return>
<argument index="0" name="enabled" type="bool">
</argument>
<description>
If [code]True[/code] set the user into overtype mode. When the user types it will override existing text.
</description>
</method>
<method name="set_selection_mode">
<return type="void" />
<argument index="0" name="mode" type="int" enum="TextEdit.SelectionMode" />

View file

@ -555,7 +555,7 @@ void CodeEdit::_handle_unicode_input(const uint32_t p_unicode) {
}
/* Remove the old character if in insert mode and no selection. */
if (is_insert_mode() && !had_selection) {
if (is_overtype_mode_enabled() && !had_selection) {
begin_complex_operation();
/* Make sure we don't try and remove empty space. */
@ -594,7 +594,7 @@ void CodeEdit::_handle_unicode_input(const uint32_t p_unicode) {
insert_text_at_caret(chr);
}
if ((is_insert_mode() && !had_selection) || (had_selection)) {
if ((is_overtype_mode_enabled() && !had_selection) || (had_selection)) {
end_complex_operation();
}
}

View file

@ -1222,12 +1222,12 @@ void TextEdit::_notification(int p_what) {
if (caret.draw_pos.x >= xmargin_beg && caret.draw_pos.x < xmargin_end) {
caret.visible = true;
if (draw_caret) {
if (caret_type == CaretType::CARET_TYPE_BLOCK || insert_mode) {
if (caret_type == CaretType::CARET_TYPE_BLOCK || overtype_mode) {
//Block or underline caret, draw trailing carets at full height.
int h = cache.font->get_height(cache.font_size);
if (t_caret != Rect2()) {
if (insert_mode) {
if (overtype_mode) {
t_caret.position.y = TS->shaped_text_get_descent(rid);
t_caret.size.y = caret_width;
} else {
@ -1238,7 +1238,7 @@ void TextEdit::_notification(int p_what) {
draw_rect(t_caret, caret_color, false);
} else { // End of the line.
if (insert_mode) {
if (overtype_mode) {
l_caret.position.y = TS->shaped_text_get_descent(rid);
l_caret.size.y = caret_width;
} else {
@ -2287,7 +2287,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
return;
}
if (k->is_action("ui_text_toggle_insert_mode", true)) {
set_insert_mode(!insert_mode);
set_overtype_mode_enabled(!overtype_mode);
accept_event();
return;
}
@ -3254,6 +3254,14 @@ void TextEdit::_update_caches() {
}
/* Text manipulation */
void TextEdit::set_overtype_mode_enabled(const bool p_enabled) {
overtype_mode = p_enabled;
update();
}
bool TextEdit::is_overtype_mode_enabled() const {
return overtype_mode;
}
// Overridable actions
void TextEdit::handle_unicode_input(const uint32_t p_unicode) {
@ -4516,15 +4524,6 @@ bool TextEdit::is_drawing_spaces() const {
return draw_spaces;
}
void TextEdit::set_insert_mode(bool p_enabled) {
insert_mode = p_enabled;
update();
}
bool TextEdit::is_insert_mode() const {
return insert_mode;
}
bool TextEdit::is_insert_text_operation() {
return (current_op.type == TextOperation::TYPE_INSERT);
}
@ -5068,6 +5067,8 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_overriding_selected_font_color"), &TextEdit::is_overriding_selected_font_color);
/* Text manipulation */
ClassDB::bind_method(D_METHOD("set_overtype_mode_enabled", "enabled"), &TextEdit::set_overtype_mode_enabled);
ClassDB::bind_method(D_METHOD("is_overtype_mode_enabled"), &TextEdit::is_overtype_mode_enabled);
// Overridable actions
ClassDB::bind_method(D_METHOD("backspace"), &TextEdit::backspace);
@ -5441,7 +5442,7 @@ void TextEdit::_handle_unicode_input(const uint32_t p_unicode) {
}
/* Remove the old character if in insert mode and no selection. */
if (insert_mode && !had_selection) {
if (overtype_mode && !had_selection) {
begin_complex_operation();
/* Make sure we don't try and remove empty space. */
@ -5455,7 +5456,7 @@ void TextEdit::_handle_unicode_input(const uint32_t p_unicode) {
const char32_t chr[2] = { (char32_t)p_unicode, 0 };
insert_text_at_caret(chr);
if ((insert_mode && !had_selection) || (had_selection)) {
if ((overtype_mode && !had_selection) || (had_selection)) {
end_complex_operation();
}
}

View file

@ -188,6 +188,8 @@ private:
};
/* Text manipulation */
bool overtype_mode = false;
String cut_copy_line = "";
/* Caret. */
@ -348,8 +350,6 @@ private:
bool scroll_past_end_of_file_enabled = false;
bool highlight_current_line = false;
bool insert_mode = false;
bool smooth_scroll_enabled = false;
bool scrolling = false;
bool dragging_minimap = false;
@ -525,6 +525,8 @@ protected:
public:
/* Text manipulation */
void set_overtype_mode_enabled(const bool p_enabled);
bool is_overtype_mode_enabled() const;
// Overridable actions
void handle_unicode_input(const uint32_t p_unicode);
@ -779,9 +781,6 @@ public:
void set_draw_spaces(bool p_draw);
bool is_drawing_spaces() const;
void set_insert_mode(bool p_enabled);
bool is_insert_mode() const;
double get_v_scroll() const;
void set_v_scroll(double p_scroll);