This commit is contained in:
Juan Linietsky 2014-11-13 00:56:36 -03:00
commit 43d0eddc3c
4 changed files with 2260 additions and 2085 deletions

View file

@ -472,8 +472,6 @@ void TextEdit::_notification(int p_what) {
if (line<0 || line>=(int)text.size())
continue;
const String &str=text[line];
int char_margin=xmargin_beg-cursor.x_ofs;
@ -1265,7 +1263,8 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
case KEY_PAGEDOWN:
case KEY_HOME:
case KEY_END:
if (k.mod.shift) // if selecting ignore
// ignore arrows if any modifiers are held (shift = selecting, others may be used for editor hotkeys)
if (k.mod.command || k.mod.shift || k.mod.alt || k.mod.command)
break;
unselect=true;
break;
@ -1360,7 +1359,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
} else if (k.mod.alt) {
#else
if (k.mod.command) {
if (k.mod.alt) {
break;
} else if (k.mod.command) {
#endif
bool prev_char=false;
int cc=cursor.column;
@ -1402,7 +1403,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
cursor_set_column(text[cursor.line].length());
} else if (k.mod.alt) {
#else
if (k.mod.command) {
if (k.mod.alt) {
break;
} else if (k.mod.command) {
#endif
bool prev_char=false;
int cc=cursor.column;
@ -1436,7 +1439,8 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
if (k.mod.shift)
_pre_shift_selection();
if (k.mod.alt)
break;
#ifdef APPLE_STYLE_KEYS
if (k.mod.command)
cursor_set_line(0);
@ -1452,7 +1456,8 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
if (k.mod.shift)
_pre_shift_selection();
if (k.mod.alt)
break;
#ifdef APPLE_STYLE_KEYS
if (k.mod.command)
cursor_set_line(text.size()-1);
@ -1867,7 +1872,6 @@ void TextEdit::_base_insert_text(int p_line, int p_char,const String& p_text,int
r_end_column=text[r_end_line].length()-postinsert_text.length();
if (!text_changed_dirty && !setting_text) {
if (is_inside_tree())
MessageQueue::get_singleton()->push_call(this,"_text_changed_emit");
text_changed_dirty=true;
@ -1920,15 +1924,12 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column,int p_to_lin
text.set(p_from_line,pre_text+post_text);
if (!text_changed_dirty && !setting_text) {
if (is_inside_tree())
MessageQueue::get_singleton()->push_call(this,"_text_changed_emit");
text_changed_dirty=true;
}
}
void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_end_line,int *r_end_column) {
if (!setting_text)
@ -2132,7 +2133,6 @@ void TextEdit::cursor_set_column(int p_col) {
adjust_viewport_to_cursor();
if (!cursor_changed_dirty) {
if (is_inside_tree())
MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit");
cursor_changed_dirty=true;
@ -2164,7 +2164,6 @@ void TextEdit::cursor_set_line(int p_row) {
if (!cursor_changed_dirty) {
if (is_inside_tree())
MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit");
cursor_changed_dirty=true;
@ -3048,9 +3047,6 @@ void TextEdit::_update_completion_candidates() {
_cancel_completion();
completion_enabled=true;
}
void TextEdit::query_code_comple() {
@ -3144,6 +3140,17 @@ void TextEdit::set_tooltip_request_func(Object *p_obj, const StringName& p_funct
tooltip_ud=p_udata;
}
void TextEdit::set_line(int line, String new_text)
{
if (line < 0 || line > text.size())
return;
text.set(line, new_text);
}
void TextEdit::insert_at(const String &p_text, int at)
{
text.insert(at, p_text);
}
void TextEdit::set_show_line_numbers(bool p_show) {
@ -3307,7 +3314,6 @@ TextEdit::TextEdit() {
auto_brace_completion_enabled=false;
}
TextEdit::~TextEdit(){
TextEdit::~TextEdit()
{
}

View file

@ -299,6 +299,7 @@ public:
void set_text(String p_text);
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_breakpoint(int p_line,bool p_breakpoint);
@ -306,6 +307,7 @@ public:
void get_breakpoints(List<int> *p_breakpoints) const;
String get_text();
String get_line(int line) const;
void set_line(int line, String new_text);
void backspace_at_cursor();
inline void set_auto_brace_completion(bool p_enabled) {

View file

@ -661,13 +661,10 @@ void ScriptEditor::_menu_option(int p_option) {
} break;
case EDIT_UNDO: {
current->get_text_edit()->undo();
} break;
case EDIT_REDO: {
current->get_text_edit()->redo();
} break;
case EDIT_CUT: {
@ -685,6 +682,163 @@ void ScriptEditor::_menu_option(int p_option) {
current->get_text_edit()->select_all();
} break;
case EDIT_MOVE_LINE_UP: {
TextEdit *tx = current->get_text_edit();
Ref<Script> scr = current->get_edited_script();
if (scr.is_null())
return;
int line_id = tx->cursor_get_line();
int next_id = line_id - 1;
if (line_id == 0 || next_id < 0)
return;
String tmp = tx->get_line(line_id);
String tmp2 = tx->get_line(next_id);
tx->set_line(next_id, tmp);
tx->set_line(line_id, tmp2);
tx->update();
tx->cursor_set_line(next_id);
} break;
case EDIT_MOVE_LINE_DOWN: {
TextEdit *tx = current->get_text_edit();
Ref<Script> scr = current->get_edited_script();
if (scr.is_null())
return;
int line_id = tx->cursor_get_line();
int next_id = line_id + 1;
if (line_id == tx->get_line_count() || next_id > tx->get_line_count())
return;
String tmp = tx->get_line(line_id);
String tmp2 = tx->get_line(next_id);
tx->set_line(next_id, tmp);
tx->set_line(line_id, tmp2);
tx->update();
tx->cursor_set_line(next_id);
} break;
case EDIT_INDENT_LEFT: {
TextEdit *tx = current->get_text_edit();
Ref<Script> scr = current->get_edited_script();
if (scr.is_null())
return;
int begin, end;
begin = tx->get_selection_from_line();
if (tx->is_selection_active())
{
end = tx->get_selection_to_line();
for (int i = begin; i <= end; i++)
{
String line_text = tx->get_line(i);
line_text = line_text.substr(1, line_text.length());
tx->set_line(i, line_text);
}
}
else
{
begin = tx->cursor_get_line();
String line_text = tx->get_line(begin);
line_text = line_text.substr(1, line_text.length());
tx->set_line(begin, line_text);
}
tx->update();
tx->deselect();
} break;
case EDIT_INDENT_RIGHT: {
TextEdit *tx = current->get_text_edit();
Ref<Script> scr = current->get_edited_script();
if (scr.is_null())
return;
int begin, end;
begin = tx->get_selection_from_line();
if (tx->is_selection_active())
{
end = tx->get_selection_to_line();
for (int i = begin; i <= end; i++)
{
String line_text = tx->get_line(i);
line_text = '\t' + line_text;
tx->set_line(i, line_text);
}
}
else
{
begin = tx->cursor_get_line();
String line_text = tx->get_line(begin);
line_text = '\t' + line_text;
tx->set_line(begin, line_text);
}
tx->update();
tx->deselect();
} break;
case EDIT_CLONE_DOWN: {
TextEdit *tx = current->get_text_edit();
Ref<Script> scr = current->get_edited_script();
if (scr.is_null())
return;
int line = tx->cursor_get_line();
int next_line = line + 1;
if (line == tx->get_line_count() || next_line > tx->get_line_count())
return;
String line_clone = tx->get_line(line);
tx->insert_at(line_clone, next_line);
tx->update();
} break;
case EDIT_TOGGLE_COMMENT: {
TextEdit *tx = current->get_text_edit();
Ref<Script> scr = current->get_edited_script();
if (scr.is_null())
return;
int begin, end;
begin = tx->get_selection_from_line();
if (tx->is_selection_active())
{
end = tx->get_selection_to_line();
for (int i = begin; i <= end; i++)
{
String line_text = tx->get_line(i);
if (line_text.begins_with("#"))
line_text = line_text.strip_edges().substr(1, line_text.length());
else
line_text = "#" + line_text;
tx->set_line(i, line_text);
}
}
else
{
begin = tx->cursor_get_line();
String line_text = tx->get_line(begin);
if (line_text.begins_with("#"))
line_text = line_text.strip_edges().substr(1, line_text.length());
else
line_text = "#" + line_text;
tx->set_line(begin, line_text);
}
tx->update();
tx->deselect();
} break;
case EDIT_COMPLETE: {
@ -1335,8 +1489,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
edit_menu = memnew( MenuButton );
menu_hb->add_child(edit_menu);
edit_menu->set_text("Edit");
edit_menu->get_popup()->add_item("Undo");
edit_menu->get_popup()->add_item("Redo");
edit_menu->get_popup()->add_item("Undo",EDIT_UNDO,KEY_MASK_CMD|KEY_Z);
edit_menu->get_popup()->add_item("Redo",EDIT_REDO,KEY_MASK_CMD|KEY_Y);
edit_menu->get_popup()->add_separator();
edit_menu->get_popup()->add_item("Cut",EDIT_CUT,KEY_MASK_CMD|KEY_X);
edit_menu->get_popup()->add_item("Copy",EDIT_COPY,KEY_MASK_CMD|KEY_C);
@ -1344,6 +1498,13 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
edit_menu->get_popup()->add_separator();
edit_menu->get_popup()->add_item("Select All",EDIT_SELECT_ALL,KEY_MASK_CMD|KEY_A);
edit_menu->get_popup()->add_separator();
edit_menu->get_popup()->add_item("Move Line Up",EDIT_MOVE_LINE_UP,KEY_MASK_ALT|KEY_UP);
edit_menu->get_popup()->add_item("Move Line Down",EDIT_MOVE_LINE_DOWN,KEY_MASK_ALT|KEY_DOWN);
edit_menu->get_popup()->add_item("Indent Left",EDIT_INDENT_LEFT,KEY_MASK_ALT|KEY_LEFT);
edit_menu->get_popup()->add_item("Indent Right",EDIT_INDENT_RIGHT,KEY_MASK_ALT|KEY_RIGHT);
edit_menu->get_popup()->add_item("Toggle Comment",EDIT_TOGGLE_COMMENT,KEY_MASK_CMD|KEY_SLASH);
edit_menu->get_popup()->add_item("Clone Down",EDIT_CLONE_DOWN,KEY_MASK_CMD|KEY_B);
edit_menu->get_popup()->add_separator();
edit_menu->get_popup()->add_item("Complete Symbol",EDIT_COMPLETE,KEY_MASK_CMD|KEY_SPACE);
edit_menu->get_popup()->add_item("Auto Indent",EDIT_AUTO_INDENT,KEY_MASK_CMD|KEY_I);
edit_menu->get_popup()->connect("item_pressed", this,"_menu_option");

View file

@ -123,6 +123,12 @@ class ScriptEditor : public VBoxContainer {
EDIT_SELECT_ALL,
EDIT_COMPLETE,
EDIT_AUTO_INDENT,
EDIT_TOGGLE_COMMENT,
EDIT_MOVE_LINE_UP,
EDIT_MOVE_LINE_DOWN,
EDIT_INDENT_RIGHT,
EDIT_INDENT_LEFT,
EDIT_CLONE_DOWN,
SEARCH_FIND,
SEARCH_FIND_NEXT,
SEARCH_REPLACE,