2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* text_edit.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 00:11:42 +02:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#include "text_edit.h"
|
2015-12-09 19:56:41 +01:00
|
|
|
#include "os/input.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "os/keyboard.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "os/os.h"
|
2014-11-12 15:39:21 +01:00
|
|
|
|
2017-02-21 04:05:15 +01:00
|
|
|
#include "global_config.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "message_queue.h"
|
2016-09-11 16:28:01 +02:00
|
|
|
#include "scene/main/viewport.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-04-27 12:34:37 +02:00
|
|
|
#define TAB_PIXELS
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
static bool _is_text_char(CharType c) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool _is_symbol(CharType c) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return c != '_' && ((c >= '!' && c <= '/') || (c >= ':' && c <= '@') || (c >= '[' && c <= '`') || (c >= '{' && c <= '~') || c == '\t' || c == ' ');
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-03-21 16:45:38 +01:00
|
|
|
static bool _is_char(CharType c) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
|
2016-03-21 16:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool _is_number(CharType c) {
|
|
|
|
return (c >= '0' && c <= '9');
|
|
|
|
}
|
|
|
|
|
2016-05-15 02:32:43 +02:00
|
|
|
static bool _is_hex_symbol(CharType c) {
|
|
|
|
return ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
|
|
|
|
}
|
|
|
|
|
2014-04-27 12:34:37 +02:00
|
|
|
static bool _is_pair_right_symbol(CharType c) {
|
2017-03-05 16:44:50 +01:00
|
|
|
return c == '"' ||
|
|
|
|
c == '\'' ||
|
|
|
|
c == ')' ||
|
|
|
|
c == ']' ||
|
|
|
|
c == '}';
|
2014-04-27 12:34:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool _is_pair_left_symbol(CharType c) {
|
2017-03-05 16:44:50 +01:00
|
|
|
return c == '"' ||
|
|
|
|
c == '\'' ||
|
|
|
|
c == '(' ||
|
|
|
|
c == '[' ||
|
|
|
|
c == '{';
|
2014-04-27 12:34:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool _is_pair_symbol(CharType c) {
|
2015-01-02 19:08:40 +01:00
|
|
|
return _is_pair_left_symbol(c) || _is_pair_right_symbol(c);
|
2014-04-27 12:34:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static CharType _get_right_pair_symbol(CharType c) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (c == '"')
|
2015-01-02 19:08:40 +01:00
|
|
|
return '"';
|
2017-03-05 16:44:50 +01:00
|
|
|
if (c == '\'')
|
2015-01-02 19:08:40 +01:00
|
|
|
return '\'';
|
2017-03-05 16:44:50 +01:00
|
|
|
if (c == '(')
|
2015-01-02 19:08:40 +01:00
|
|
|
return ')';
|
2017-03-05 16:44:50 +01:00
|
|
|
if (c == '[')
|
2015-01-02 19:08:40 +01:00
|
|
|
return ']';
|
2017-03-05 16:44:50 +01:00
|
|
|
if (c == '{')
|
2015-01-02 19:08:40 +01:00
|
|
|
return '}';
|
|
|
|
return 0;
|
2014-04-27 12:34:37 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::Text::set_font(const Ref<Font> &p_font) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
font = p_font;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-17 15:24:30 +02:00
|
|
|
void TextEdit::Text::set_indent_size(int p_indent_size) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-04-17 15:24:30 +02:00
|
|
|
indent_size = p_indent_size;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::Text::_update_line_cache(int p_line) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-09-09 18:44:31 +02:00
|
|
|
int w = 0;
|
2017-04-17 15:24:30 +02:00
|
|
|
int tab_w = font->get_char_size(' ').width * indent_size;
|
2015-09-09 18:44:31 +02:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
int len = text[p_line].data.length();
|
|
|
|
const CharType *str = text[p_line].data.c_str();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
//update width
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
if (str[i] == '\t') {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int left = w % tab_w;
|
|
|
|
if (left == 0)
|
|
|
|
w += tab_w;
|
2015-01-02 19:08:40 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
w += tab_w - w % tab_w; // is right...
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
w += font->get_char_size(str[i], str[i + 1]).width;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
text[p_line].width_cache = w;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
//update regions
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
text[p_line].region_info.clear();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!_is_symbol(str[i]))
|
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (str[i] == '\\') {
|
2015-01-02 19:08:40 +01:00
|
|
|
i++; //skip quoted anything
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int left = len - i;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < color_regions->size(); j++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const ColorRegion &cr = color_regions->operator[](j);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
/* BEGIN */
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int lr = cr.begin_key.length();
|
|
|
|
if (lr == 0 || lr > left)
|
2015-01-02 19:08:40 +01:00
|
|
|
continue;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const CharType *kc = cr.begin_key.c_str();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool match = true;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int k = 0; k < lr; k++) {
|
|
|
|
if (kc[k] != str[i + k]) {
|
|
|
|
match = false;
|
2015-01-02 19:08:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (match) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
ColorRegionInfo cri;
|
2017-03-05 16:44:50 +01:00
|
|
|
cri.end = false;
|
|
|
|
cri.region = j;
|
|
|
|
text[p_line].region_info[i] = cri;
|
|
|
|
i += lr - 1;
|
2015-01-02 19:08:40 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
/* END */
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
lr = cr.end_key.length();
|
|
|
|
if (lr == 0 || lr > left)
|
2015-01-02 19:08:40 +01:00
|
|
|
continue;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
kc = cr.end_key.c_str();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
match = true;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int k = 0; k < lr; k++) {
|
|
|
|
if (kc[k] != str[i + k]) {
|
|
|
|
match = false;
|
2015-01-02 19:08:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (match) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
ColorRegionInfo cri;
|
2017-03-05 16:44:50 +01:00
|
|
|
cri.end = true;
|
|
|
|
cri.region = j;
|
|
|
|
text[p_line].region_info[i] = cri;
|
|
|
|
i += lr - 1;
|
2015-01-02 19:08:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Map<int, TextEdit::Text::ColorRegionInfo> &TextEdit::Text::get_color_region_info(int p_line) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<int, ColorRegionInfo> *cri = NULL;
|
|
|
|
ERR_FAIL_INDEX_V(p_line, text.size(), *cri); //enjoy your crash
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (text[p_line].width_cache == -1) {
|
2015-01-02 19:08:40 +01:00
|
|
|
_update_line_cache(p_line);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return text[p_line].region_info;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TextEdit::Text::get_line_width(int p_line) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_line, text.size(), -1);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (text[p_line].width_cache == -1) {
|
2015-01-02 19:08:40 +01:00
|
|
|
_update_line_cache(p_line);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return text[p_line].width_cache;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::Text::clear_caches() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < text.size(); i++)
|
|
|
|
text[i].width_cache = -1;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::Text::clear() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-14 18:03:38 +01:00
|
|
|
text.clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
insert(0, "");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TextEdit::Text::get_max_width() const {
|
2015-01-02 19:08:40 +01:00
|
|
|
//quite some work.. but should be fast enough.
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
int max = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < text.size(); i++)
|
|
|
|
max = MAX(max, get_line_width(i));
|
2015-01-02 19:08:40 +01:00
|
|
|
return max;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::Text::set(int p_line, const String &p_text) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(p_line, text.size());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
text[p_line].width_cache = -1;
|
|
|
|
text[p_line].data = p_text;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::Text::insert(int p_at, const String &p_text) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
Line line;
|
2017-03-05 16:44:50 +01:00
|
|
|
line.marked = false;
|
|
|
|
line.breakpoint = false;
|
|
|
|
line.width_cache = -1;
|
|
|
|
line.data = p_text;
|
|
|
|
text.insert(p_at, line);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
void TextEdit::Text::remove(int p_at) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
text.remove(p_at);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::_update_scrollbars() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
Size2 size = get_size();
|
|
|
|
Size2 hmin = h_scroll->get_combined_minimum_size();
|
|
|
|
Size2 vmin = v_scroll->get_combined_minimum_size();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
v_scroll->set_begin(Point2(size.width - vmin.width, cache.style_normal->get_margin(MARGIN_TOP)));
|
|
|
|
v_scroll->set_end(Point2(size.width, size.height - cache.style_normal->get_margin(MARGIN_TOP) - cache.style_normal->get_margin(MARGIN_BOTTOM)));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
h_scroll->set_begin(Point2(0, size.height - hmin.height));
|
|
|
|
h_scroll->set_end(Point2(size.width - vmin.width, size.height));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int hscroll_rows = ((hmin.height - 1) / get_row_height()) + 1;
|
2015-01-02 19:08:40 +01:00
|
|
|
int visible_rows = get_visible_rows();
|
2015-01-13 10:16:56 +01:00
|
|
|
int total_rows = text.size();
|
2016-03-07 03:32:51 +01:00
|
|
|
if (scroll_past_end_of_file_enabled) {
|
|
|
|
total_rows += get_visible_rows() - 1;
|
|
|
|
}
|
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
int vscroll_pixels = v_scroll->get_combined_minimum_size().width;
|
|
|
|
int visible_width = size.width - cache.style_normal->get_minimum_size().width;
|
2015-09-09 18:44:31 +02:00
|
|
|
int total_width = text.get_max_width() + vmin.x;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-09-09 18:44:31 +02:00
|
|
|
if (line_numbers)
|
|
|
|
total_width += cache.line_number_w;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-05-26 15:17:14 +02:00
|
|
|
if (draw_breakpoint_gutter) {
|
|
|
|
total_width += cache.breakpoint_gutter_width;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool use_hscroll = true;
|
|
|
|
bool use_vscroll = true;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (total_rows <= visible_rows && total_width <= visible_width) {
|
|
|
|
//thanks yessopie for this clever bit of logic
|
2017-03-05 16:44:50 +01:00
|
|
|
use_hscroll = false;
|
|
|
|
use_vscroll = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (total_rows > visible_rows && total_width <= visible_width - vscroll_pixels) {
|
|
|
|
//thanks yessopie for this clever bit of logic
|
2017-03-05 16:44:50 +01:00
|
|
|
use_hscroll = false;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (total_rows <= visible_rows - hscroll_rows && total_width > visible_width) {
|
|
|
|
//thanks yessopie for this clever bit of logic
|
2017-03-05 16:44:50 +01:00
|
|
|
use_vscroll = false;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating_scrolls = true;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (use_vscroll) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
v_scroll->show();
|
|
|
|
v_scroll->set_max(total_rows);
|
|
|
|
v_scroll->set_page(visible_rows);
|
2017-02-21 23:45:31 +01:00
|
|
|
|
|
|
|
if (fabs(v_scroll->get_value() - (double)cursor.line_ofs) >= 1) {
|
|
|
|
v_scroll->set_value(cursor.line_ofs);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else {
|
2015-01-02 19:08:40 +01:00
|
|
|
cursor.line_ofs = 0;
|
|
|
|
v_scroll->hide();
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (use_hscroll) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
h_scroll->show();
|
|
|
|
h_scroll->set_max(total_width);
|
|
|
|
h_scroll->set_page(visible_width);
|
2017-02-21 23:45:31 +01:00
|
|
|
if (fabs(h_scroll->get_value() - (double)cursor.x_ofs) >= 1) {
|
|
|
|
h_scroll->set_value(cursor.x_ofs);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
h_scroll->hide();
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating_scrolls = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-12-09 19:56:41 +01:00
|
|
|
void TextEdit::_click_selection_held() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && selection.selecting_mode != Selection::MODE_NONE) {
|
2015-12-09 19:56:41 +01:00
|
|
|
|
2017-03-29 17:29:38 +02:00
|
|
|
Point2 mp = Input::get_singleton()->get_mouse_position() - get_global_position();
|
2015-12-09 19:56:41 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int row, col;
|
|
|
|
_get_mouse_pos(Point2i(mp.x, mp.y), row, col);
|
2015-12-09 19:56:41 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
select(selection.selecting_line, selection.selecting_column, row, col);
|
2015-12-09 19:56:41 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor_set_line(row);
|
|
|
|
cursor_set_column(col);
|
2015-12-09 19:56:41 +01:00
|
|
|
update();
|
|
|
|
|
|
|
|
click_select_held->start();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
click_select_held->stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TextEdit::_notification(int p_what) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_what) {
|
2014-12-17 02:31:57 +01:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
_update_caches();
|
|
|
|
if (cursor_changed_dirty)
|
2017-03-05 16:44:50 +01:00
|
|
|
MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
|
2014-12-17 02:31:57 +01:00
|
|
|
if (text_changed_dirty)
|
2017-03-05 16:44:50 +01:00
|
|
|
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_RESIZED: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cache.size = get_size();
|
2014-12-17 02:31:57 +01:00
|
|
|
adjust_viewport_to_cursor();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
_update_caches();
|
2016-05-29 16:37:26 +02:00
|
|
|
} break;
|
2016-06-19 17:11:16 +02:00
|
|
|
case MainLoop::NOTIFICATION_WM_FOCUS_IN: {
|
|
|
|
window_has_focus = true;
|
|
|
|
draw_caret = true;
|
|
|
|
update();
|
|
|
|
} break;
|
|
|
|
case MainLoop::NOTIFICATION_WM_FOCUS_OUT: {
|
|
|
|
window_has_focus = false;
|
|
|
|
draw_caret = false;
|
|
|
|
update();
|
|
|
|
} break;
|
2014-12-17 02:31:57 +01:00
|
|
|
case NOTIFICATION_DRAW: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-19 17:11:16 +02:00
|
|
|
if ((!has_focus() && !menu->has_focus()) || !window_has_focus) {
|
|
|
|
draw_caret = false;
|
|
|
|
}
|
|
|
|
|
2016-05-26 15:17:14 +02:00
|
|
|
if (draw_breakpoint_gutter) {
|
2016-06-07 17:59:16 +02:00
|
|
|
breakpoint_gutter_width = (get_row_height() * 55) / 100;
|
2016-05-26 15:17:14 +02:00
|
|
|
cache.breakpoint_gutter_width = breakpoint_gutter_width;
|
|
|
|
} else {
|
|
|
|
cache.breakpoint_gutter_width = 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int line_number_char_count = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
{
|
2017-03-05 16:44:50 +01:00
|
|
|
int lc = text.size() + 1;
|
|
|
|
cache.line_number_w = 0;
|
|
|
|
while (lc) {
|
|
|
|
cache.line_number_w += 1;
|
|
|
|
lc /= 10;
|
2014-12-17 02:31:57 +01:00
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (line_numbers) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
line_number_char_count = cache.line_number_w;
|
|
|
|
cache.line_number_w = (cache.line_number_w + 1) * cache.font->get_char_size('0').width;
|
2014-12-17 02:31:57 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
cache.line_number_w = 0;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_update_scrollbars();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
RID ci = get_canvas_item();
|
2017-03-05 16:44:50 +01:00
|
|
|
int xmargin_beg = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width;
|
|
|
|
int xmargin_end = cache.size.width - cache.style_normal->get_margin(MARGIN_RIGHT);
|
2014-12-17 02:31:57 +01:00
|
|
|
//let's do it easy for now:
|
2017-03-05 16:44:50 +01:00
|
|
|
cache.style_normal->draw(ci, Rect2(Point2(), cache.size));
|
2014-12-17 02:31:57 +01:00
|
|
|
if (has_focus())
|
2017-03-05 16:44:50 +01:00
|
|
|
cache.style_focus->draw(ci, Rect2(Point2(), cache.size));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int ascent = cache.font->get_ascent();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
int visible_rows = get_visible_rows();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-04-17 15:24:30 +02:00
|
|
|
int tab_w = cache.font->get_char_size(' ').width * indent_size;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
Color color = cache.font_color;
|
2017-03-05 16:44:50 +01:00
|
|
|
int in_region = -1;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (syntax_coloring) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cache.background_color.a > 0.01) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Point2i ofs = Point2i(cache.style_normal->get_offset()) / 2.0;
|
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(ofs, get_size() - cache.style_normal->get_minimum_size() + ofs), cache.background_color);
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
|
|
|
//compute actual region to start (may be inside say, a comment).
|
|
|
|
//slow in very large documments :( but ok for source!
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < cursor.line_ofs; i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Map<int, Text::ColorRegionInfo> &cri_map = text.get_color_region_info(i);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (in_region >= 0 && color_regions[in_region].line_only) {
|
|
|
|
in_region = -1; //reset regions that end at end of line
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (const Map<int, Text::ColorRegionInfo>::Element *E = cri_map.front(); E; E = E->next()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Text::ColorRegionInfo &cri = E->get();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (in_region == -1) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (!cri.end) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
in_region = cri.region;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (in_region == cri.region && !color_regions[cri.region].line_only) { //ignore otherwise
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (cri.end || color_regions[cri.region].eq) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
in_region = -1;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int brace_open_match_line = -1;
|
|
|
|
int brace_open_match_column = -1;
|
|
|
|
bool brace_open_matching = false;
|
|
|
|
bool brace_open_mismatch = false;
|
|
|
|
int brace_close_match_line = -1;
|
|
|
|
int brace_close_match_column = -1;
|
|
|
|
bool brace_close_matching = false;
|
|
|
|
bool brace_close_mismatch = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 05:53:34 +01:00
|
|
|
if (brace_matching_enabled) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.column < text[cursor.line].length()) {
|
2014-12-17 05:53:34 +01:00
|
|
|
//check for open
|
|
|
|
CharType c = text[cursor.line][cursor.column];
|
2017-03-05 16:44:50 +01:00
|
|
|
CharType closec = 0;
|
|
|
|
|
|
|
|
if (c == '[') {
|
|
|
|
closec = ']';
|
|
|
|
} else if (c == '{') {
|
|
|
|
closec = '}';
|
|
|
|
} else if (c == '(') {
|
|
|
|
closec = ')';
|
2014-12-17 05:53:34 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (closec != 0) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int stack = 1;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = cursor.line; i < text.size(); i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int from = i == cursor.line ? cursor.column + 1 : 0;
|
|
|
|
for (int j = from; j < text[i].length(); j++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 05:53:34 +01:00
|
|
|
CharType cc = text[i][j];
|
2015-02-20 01:34:04 +01:00
|
|
|
//ignore any brackets inside a string
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cc == '"' || cc == '\'') {
|
2015-02-20 01:34:04 +01:00
|
|
|
CharType quotation = cc;
|
|
|
|
do {
|
|
|
|
j++;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!(j < text[i].length())) {
|
2015-02-20 01:34:04 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
cc = text[i][j];
|
2015-02-20 01:34:04 +01:00
|
|
|
//skip over escaped quotation marks inside strings
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cc == '\\') {
|
2015-02-20 01:34:04 +01:00
|
|
|
bool escaped = true;
|
2017-03-05 16:44:50 +01:00
|
|
|
while (j + 1 < text[i].length() && text[i][j + 1] == '\\') {
|
|
|
|
escaped = !escaped;
|
2015-02-20 01:34:04 +01:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
if (escaped) {
|
|
|
|
j++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
} while (cc != quotation);
|
|
|
|
} else if (cc == c)
|
2014-12-17 05:53:34 +01:00
|
|
|
stack++;
|
2017-03-05 16:44:50 +01:00
|
|
|
else if (cc == closec)
|
2014-12-17 05:53:34 +01:00
|
|
|
stack--;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (stack == 0) {
|
|
|
|
brace_open_match_line = i;
|
|
|
|
brace_open_match_column = j;
|
|
|
|
brace_open_matching = true;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 05:53:34 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (brace_open_match_line != -1)
|
2014-12-17 05:53:34 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 05:53:34 +01:00
|
|
|
if (!brace_open_matching)
|
2017-03-05 16:44:50 +01:00
|
|
|
brace_open_mismatch = true;
|
2014-12-17 05:53:34 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.column > 0) {
|
|
|
|
CharType c = text[cursor.line][cursor.column - 1];
|
|
|
|
CharType closec = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (c == ']') {
|
|
|
|
closec = '[';
|
|
|
|
} else if (c == '}') {
|
|
|
|
closec = '{';
|
|
|
|
} else if (c == ')') {
|
|
|
|
closec = '(';
|
2014-12-17 05:53:34 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (closec != 0) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int stack = 1;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = cursor.line; i >= 0; i--) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int from = i == cursor.line ? cursor.column - 2 : text[i].length() - 1;
|
|
|
|
for (int j = from; j >= 0; j--) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 05:53:34 +01:00
|
|
|
CharType cc = text[i][j];
|
2015-02-20 01:34:04 +01:00
|
|
|
//ignore any brackets inside a string
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cc == '"' || cc == '\'') {
|
2015-02-20 01:34:04 +01:00
|
|
|
CharType quotation = cc;
|
|
|
|
do {
|
|
|
|
j--;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!(j >= 0)) {
|
2015-02-20 01:34:04 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
cc = text[i][j];
|
2015-02-20 01:34:04 +01:00
|
|
|
//skip over escaped quotation marks inside strings
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cc == quotation) {
|
2015-02-20 01:34:04 +01:00
|
|
|
bool escaped = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
while (j - 1 >= 0 && text[i][j - 1] == '\\') {
|
|
|
|
escaped = !escaped;
|
2015-02-20 01:34:04 +01:00
|
|
|
j--;
|
|
|
|
}
|
|
|
|
if (escaped) {
|
|
|
|
j--;
|
2017-03-05 16:44:50 +01:00
|
|
|
cc = '\\';
|
2015-02-20 01:34:04 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
} while (cc != quotation);
|
|
|
|
} else if (cc == c)
|
2014-12-17 05:53:34 +01:00
|
|
|
stack++;
|
2017-03-05 16:44:50 +01:00
|
|
|
else if (cc == closec)
|
2014-12-17 05:53:34 +01:00
|
|
|
stack--;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (stack == 0) {
|
|
|
|
brace_close_match_line = i;
|
|
|
|
brace_close_match_column = j;
|
|
|
|
brace_close_matching = true;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 05:53:34 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (brace_close_match_line != -1)
|
2014-12-17 05:53:34 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 05:53:34 +01:00
|
|
|
if (!brace_close_matching)
|
2017-03-05 16:44:50 +01:00
|
|
|
brace_close_mismatch = true;
|
2014-12-17 05:53:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int deregion = 0; //force it to clear inrgion
|
2014-12-17 02:31:57 +01:00
|
|
|
Point2 cursor_pos;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-16 22:20:42 +01:00
|
|
|
// get the highlighted words
|
2016-03-17 20:37:19 +01:00
|
|
|
String highlighted_text = get_selection_text();
|
2016-03-16 22:20:42 +01:00
|
|
|
|
2016-10-10 13:43:09 +02:00
|
|
|
String line_num_padding = line_numbers_zero_padded ? "0" : " ";
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < visible_rows; i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int line = i + cursor.line_ofs;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (line < 0 || line >= (int)text.size())
|
2014-12-17 02:31:57 +01:00
|
|
|
continue;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const String &str = text[line];
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int char_margin = xmargin_beg - cursor.x_ofs;
|
|
|
|
int char_ofs = 0;
|
|
|
|
int ofs_y = i * get_row_height() + cache.line_spacing / 2;
|
|
|
|
bool prev_is_char = false;
|
2016-03-21 16:45:38 +01:00
|
|
|
bool prev_is_number = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
bool in_keyword = false;
|
|
|
|
bool underlined = false;
|
2016-03-21 16:45:38 +01:00
|
|
|
bool in_word = false;
|
2016-04-02 21:46:42 +02:00
|
|
|
bool in_function_name = false;
|
2016-04-05 16:50:54 +02:00
|
|
|
bool in_member_variable = false;
|
2016-05-15 02:32:43 +02:00
|
|
|
bool is_hex_notation = false;
|
2014-12-17 02:31:57 +01:00
|
|
|
Color keyword_color;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-16 22:20:42 +01:00
|
|
|
// check if line contains highlighted word
|
|
|
|
int highlighted_text_col = -1;
|
2016-05-28 18:25:45 +02:00
|
|
|
int search_text_col = -1;
|
|
|
|
|
|
|
|
if (!search_text.empty())
|
|
|
|
search_text_col = _get_column_pos_of_word(search_text, str, search_flags, 0);
|
|
|
|
|
|
|
|
if (highlighted_text.length() != 0 && highlighted_text != search_text)
|
2017-03-05 16:44:50 +01:00
|
|
|
highlighted_text_col = _get_column_pos_of_word(highlighted_text, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Map<int, Text::ColorRegionInfo> &cri_map = text.get_color_region_info(line);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (text.is_marked(line)) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.mark_color);
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (text.is_breakpoint(line)) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg, ofs_y, xmargin_end - xmargin_beg, get_row_height()), cache.breakpoint_color);
|
2016-05-30 17:28:31 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (line == cursor.line) {
|
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_end, get_row_height()), cache.current_line_color);
|
2016-05-30 17:28:31 +02:00
|
|
|
}
|
2016-05-26 15:17:14 +02:00
|
|
|
|
2016-05-30 17:28:31 +02:00
|
|
|
// draw breakpoint marker
|
|
|
|
if (text.is_breakpoint(line)) {
|
2016-05-26 15:17:14 +02:00
|
|
|
if (draw_breakpoint_gutter) {
|
2016-06-07 17:59:16 +02:00
|
|
|
int vertical_gap = (get_row_height() * 40) / 100;
|
|
|
|
int horizontal_gap = (cache.breakpoint_gutter_width * 30) / 100;
|
|
|
|
int marker_height = get_row_height() - (vertical_gap * 2);
|
|
|
|
int marker_width = cache.breakpoint_gutter_width - (horizontal_gap * 2);
|
2016-05-26 15:17:14 +02:00
|
|
|
// no transparency on marker
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cache.style_normal->get_margin(MARGIN_LEFT) + horizontal_gap - 2, ofs_y + vertical_gap, marker_width, marker_height), Color(cache.breakpoint_color.r, cache.breakpoint_color.g, cache.breakpoint_color.b));
|
2016-05-26 15:17:14 +02:00
|
|
|
}
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-05-30 17:28:31 +02:00
|
|
|
if (cache.line_number_w) {
|
2017-03-05 16:44:50 +01:00
|
|
|
String fc = String::num(line + 1);
|
2016-05-30 17:28:31 +02:00
|
|
|
while (fc.length() < line_number_char_count) {
|
2017-03-05 16:44:50 +01:00
|
|
|
fc = line_num_padding + fc;
|
2016-05-30 17:28:31 +02:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cache.font->draw(ci, Point2(cache.style_normal->get_margin(MARGIN_LEFT) + cache.breakpoint_gutter_width, ofs_y + cache.font->get_ascent()), fc, cache.line_number_color);
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < str.length(); j++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
//look for keyword
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (deregion > 0) {
|
2014-12-17 02:31:57 +01:00
|
|
|
deregion--;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (deregion == 0)
|
|
|
|
in_region = -1;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (syntax_coloring && deregion == 0) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
color = cache.font_color; //reset
|
|
|
|
//find keyword
|
2017-03-05 16:44:50 +01:00
|
|
|
bool is_char = _is_text_char(str[j]);
|
2016-03-21 16:45:38 +01:00
|
|
|
bool is_symbol = _is_symbol(str[j]);
|
|
|
|
bool is_number = _is_number(str[j]);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (j == 0 && in_region >= 0 && color_regions[in_region].line_only) {
|
|
|
|
in_region = -1; //reset regions that end at end of line
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-05-15 02:32:43 +02:00
|
|
|
// allow ABCDEF in hex notation
|
|
|
|
if (is_hex_notation && (_is_hex_symbol(str[j]) || is_number)) {
|
|
|
|
is_number = true;
|
|
|
|
} else {
|
|
|
|
is_hex_notation = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for dot or 'x' for hex notation in floating point number
|
2017-03-05 16:44:50 +01:00
|
|
|
if ((str[j] == '.' || str[j] == 'x') && !in_word && prev_is_number && !is_number) {
|
2016-05-15 02:32:43 +02:00
|
|
|
is_number = true;
|
|
|
|
is_symbol = false;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (str[j] == 'x' && str[j - 1] == '0') {
|
2016-05-15 02:32:43 +02:00
|
|
|
is_hex_notation = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-21 16:45:38 +01:00
|
|
|
if (!in_word && _is_char(str[j])) {
|
|
|
|
in_word = true;
|
|
|
|
}
|
|
|
|
|
2016-05-15 02:32:43 +02:00
|
|
|
if ((in_keyword || in_word) && !is_hex_notation) {
|
2016-03-21 16:45:38 +01:00
|
|
|
is_number = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_symbol && str[j] != '.' && in_word) {
|
|
|
|
in_word = false;
|
|
|
|
}
|
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (is_symbol && cri_map.has(j)) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Text::ColorRegionInfo &cri = cri_map[j];
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (in_region == -1) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (!cri.end) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
in_region = cri.region;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (in_region == cri.region && !color_regions[cri.region].line_only) { //ignore otherwise
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (cri.end || color_regions[cri.region].eq) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
deregion = color_regions[cri.region].eq ? color_regions[cri.region].begin_key.length() : color_regions[cri.region].end_key.length();
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-09-12 15:52:29 +02:00
|
|
|
if (!is_char) {
|
2017-03-05 16:44:50 +01:00
|
|
|
in_keyword = false;
|
|
|
|
underlined = false;
|
2016-09-12 15:52:29 +02:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (in_region == -1 && !in_keyword && is_char && !prev_is_char) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int to = j;
|
|
|
|
while (to < str.length() && _is_text_char(str[to]))
|
2014-12-17 02:31:57 +01:00
|
|
|
to++;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uint32_t hash = String::hash(&str[j], to - j);
|
|
|
|
StrRange range(&str[j], to - j);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Color *col = keywords.custom_getptr(range, hash);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (col) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
in_keyword = true;
|
|
|
|
keyword_color = *col;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-04-06 17:35:08 +02:00
|
|
|
if (select_identifiers_enabled && highlighted_word != String()) {
|
|
|
|
if (highlighted_word == range) {
|
2017-03-05 16:44:50 +01:00
|
|
|
underlined = true;
|
2016-09-12 15:52:29 +02:00
|
|
|
}
|
|
|
|
}
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-04-02 21:46:42 +02:00
|
|
|
if (!in_function_name && in_word && !in_keyword) {
|
|
|
|
|
|
|
|
int k = j;
|
2017-03-05 16:44:50 +01:00
|
|
|
while (k < str.length() && !_is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') {
|
2016-04-02 21:46:42 +02:00
|
|
|
k++;
|
|
|
|
}
|
|
|
|
|
2016-06-29 15:07:11 +02:00
|
|
|
// check for space between name and bracket
|
|
|
|
while (k < str.length() && (str[k] == '\t' || str[k] == ' ')) {
|
|
|
|
k++;
|
|
|
|
}
|
|
|
|
|
2016-04-02 21:46:42 +02:00
|
|
|
if (str[k] == '(') {
|
|
|
|
in_function_name = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-05 16:50:54 +02:00
|
|
|
if (!in_function_name && !in_member_variable && !in_keyword && !is_number && in_word) {
|
|
|
|
int k = j;
|
2017-03-05 16:44:50 +01:00
|
|
|
while (k > 0 && !_is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') {
|
2016-04-05 16:50:54 +02:00
|
|
|
k--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str[k] == '.') {
|
|
|
|
in_member_variable = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-02 21:46:42 +02:00
|
|
|
if (is_symbol) {
|
|
|
|
in_function_name = false;
|
2016-04-05 16:50:54 +02:00
|
|
|
in_member_variable = false;
|
2016-04-02 21:46:42 +02:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (in_region >= 0)
|
|
|
|
color = color_regions[in_region].color;
|
2014-12-17 02:31:57 +01:00
|
|
|
else if (in_keyword)
|
2017-03-05 16:44:50 +01:00
|
|
|
color = keyword_color;
|
2016-04-05 16:50:54 +02:00
|
|
|
else if (in_member_variable)
|
2017-03-05 16:44:50 +01:00
|
|
|
color = cache.member_variable_color;
|
2016-04-02 21:46:42 +02:00
|
|
|
else if (in_function_name)
|
2017-03-05 16:44:50 +01:00
|
|
|
color = cache.function_color;
|
2014-12-17 02:31:57 +01:00
|
|
|
else if (is_symbol)
|
2017-03-05 16:44:50 +01:00
|
|
|
color = cache.symbol_color;
|
2016-03-21 16:45:38 +01:00
|
|
|
else if (is_number)
|
2017-03-05 16:44:50 +01:00
|
|
|
color = cache.number_color;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
prev_is_char = is_char;
|
|
|
|
prev_is_number = is_number;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
|
|
|
int char_w;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
//handle tabulator
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (str[j] == '\t') {
|
|
|
|
int left = char_ofs % tab_w;
|
|
|
|
if (left == 0)
|
|
|
|
char_w = tab_w;
|
2014-12-17 02:31:57 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
char_w = tab_w - char_ofs % tab_w; // is right...
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
char_w = cache.font->get_char_size(str[j], str[j + 1]).width;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if ((char_ofs + char_margin) < xmargin_beg) {
|
|
|
|
char_ofs += char_w;
|
2014-12-17 02:31:57 +01:00
|
|
|
continue;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if ((char_ofs + char_margin + char_w) >= xmargin_end) {
|
2014-12-17 02:31:57 +01:00
|
|
|
if (syntax_coloring)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool in_search_result = false;
|
2016-05-28 18:25:45 +02:00
|
|
|
|
|
|
|
if (search_text_col != -1) {
|
|
|
|
// if we are at the end check for new search result on same line
|
2017-03-05 16:44:50 +01:00
|
|
|
if (j >= search_text_col + search_text.length())
|
2016-05-28 18:25:45 +02:00
|
|
|
search_text_col = _get_column_pos_of_word(search_text, str, search_flags, j);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
in_search_result = j >= search_text_col && j < search_text_col + search_text.length();
|
2016-05-28 18:25:45 +02:00
|
|
|
|
|
|
|
if (in_search_result) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y), Size2i(char_w, get_row_height())), cache.search_result_color);
|
2016-05-28 18:25:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool in_selection = (selection.active && line >= selection.from_line && line <= selection.to_line && (line > selection.from_line || j >= selection.from_column) && (line < selection.to_line || j < selection.to_column));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (in_selection) {
|
|
|
|
//inside selection!
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y), Size2i(char_w, get_row_height())), cache.selection_color);
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-05-28 18:25:45 +02:00
|
|
|
if (in_search_result) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Color border_color = (line == search_result_line && j >= search_result_col && j < search_result_col + search_text.length()) ? cache.font_color : cache.search_result_border_color;
|
2016-05-28 18:25:45 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y), Size2i(char_w, 1)), border_color);
|
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y + get_row_height() - 1), Size2i(char_w, 1)), border_color);
|
2016-05-28 18:25:45 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (j == search_text_col)
|
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y), Size2i(1, get_row_height())), border_color);
|
|
|
|
if (j == search_text_col + search_text.length() - 1)
|
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin + char_w - 1, ofs_y), Size2i(1, get_row_height())), border_color);
|
2016-05-28 18:25:45 +02:00
|
|
|
}
|
|
|
|
|
2016-03-16 22:20:42 +01:00
|
|
|
if (highlight_all_occurrences) {
|
|
|
|
if (highlighted_text_col != -1) {
|
|
|
|
|
|
|
|
// if we are at the end check for new word on same line
|
2017-03-05 16:44:50 +01:00
|
|
|
if (j > highlighted_text_col + highlighted_text.length()) {
|
|
|
|
highlighted_text_col = _get_column_pos_of_word(highlighted_text, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, j);
|
2016-03-16 22:20:42 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool in_highlighted_word = (j >= highlighted_text_col && j < highlighted_text_col + highlighted_text.length());
|
2016-07-10 17:10:54 +02:00
|
|
|
|
|
|
|
/* if this is the original highlighted text we don't want to highlight it again */
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.line == line && (cursor.column >= highlighted_text_col && cursor.column <= highlighted_text_col + highlighted_text.length())) {
|
2016-07-10 17:10:54 +02:00
|
|
|
in_highlighted_word = false;
|
|
|
|
}
|
|
|
|
|
2016-03-16 22:20:42 +01:00
|
|
|
if (in_highlighted_word) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2i(char_ofs + char_margin, ofs_y), Size2i(char_w, get_row_height())), cache.word_highlighted_color);
|
2016-03-16 22:20:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 05:53:34 +01:00
|
|
|
if (brace_matching_enabled) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if ((brace_open_match_line == line && brace_open_match_column == j) ||
|
|
|
|
(cursor.column == j && cursor.line == line && (brace_open_matching || brace_open_mismatch))) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 05:53:34 +01:00
|
|
|
if (brace_open_mismatch)
|
2017-03-05 16:44:50 +01:00
|
|
|
color = cache.brace_mismatch_color;
|
|
|
|
cache.font->draw_char(ci, Point2i(char_ofs + char_margin, ofs_y + ascent), '_', str[j + 1], in_selection ? cache.font_selected_color : color);
|
2014-12-17 05:53:34 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 05:53:34 +01:00
|
|
|
if (
|
2017-03-05 16:44:50 +01:00
|
|
|
(brace_close_match_line == line && brace_close_match_column == j) ||
|
|
|
|
(cursor.column == j + 1 && cursor.line == line && (brace_close_matching || brace_close_mismatch))) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 05:53:34 +01:00
|
|
|
if (brace_close_mismatch)
|
2017-03-05 16:44:50 +01:00
|
|
|
color = cache.brace_mismatch_color;
|
|
|
|
cache.font->draw_char(ci, Point2i(char_ofs + char_margin, ofs_y + ascent), '_', str[j + 1], in_selection ? cache.font_selected_color : color);
|
2014-12-17 05:53:34 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.column == j && cursor.line == line) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor_pos = Point2i(char_ofs + char_margin, ofs_y);
|
2016-05-09 20:21:55 +02:00
|
|
|
|
2016-03-31 21:49:30 +02:00
|
|
|
if (insert_mode) {
|
2016-07-12 17:07:17 +02:00
|
|
|
cursor_pos.y += (get_row_height() - 3);
|
2016-03-31 21:49:30 +02:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int caret_w = (str[j] == '\t') ? cache.font->get_char_size(' ').width : char_w;
|
2016-05-09 20:21:55 +02:00
|
|
|
if (draw_caret) {
|
|
|
|
if (insert_mode) {
|
2016-07-12 17:07:17 +02:00
|
|
|
int caret_h = (block_caret) ? 4 : 1;
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, caret_h)), cache.caret_color);
|
2016-05-09 20:21:55 +02:00
|
|
|
} else {
|
2016-07-18 16:15:40 +02:00
|
|
|
caret_w = (block_caret) ? caret_w : 1;
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, get_row_height())), cache.caret_color);
|
2016-05-09 20:21:55 +02:00
|
|
|
}
|
|
|
|
}
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.column == j && cursor.line == line && block_caret && draw_caret && !insert_mode) {
|
2016-07-12 17:07:17 +02:00
|
|
|
color = cache.caret_background_color;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (str[j] >= 32) {
|
|
|
|
int w = cache.font->draw_char(ci, Point2i(char_ofs + char_margin, ofs_y + ascent), str[j], str[j + 1], in_selection ? cache.font_selected_color : color);
|
2016-09-12 15:52:29 +02:00
|
|
|
if (underlined) {
|
2017-03-05 16:44:50 +01:00
|
|
|
draw_rect(Rect2(char_ofs + char_margin, ofs_y + ascent + 2, w, 1), in_selection ? cache.font_selected_color : color);
|
2016-09-12 15:52:29 +02:00
|
|
|
}
|
|
|
|
}
|
2016-07-12 17:07:17 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
else if (draw_tabs && str[j] == '\t') {
|
|
|
|
int yofs = (get_row_height() - cache.tab_icon->get_height()) / 2;
|
|
|
|
cache.tab_icon->draw(ci, Point2(char_ofs + char_margin, ofs_y + yofs), in_selection ? cache.font_selected_color : color);
|
2016-07-12 17:07:17 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
char_ofs += char_w;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.column == str.length() && cursor.line == line && (char_ofs + char_margin) >= xmargin_beg) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor_pos = Point2i(char_ofs + char_margin, ofs_y);
|
2016-05-09 20:21:55 +02:00
|
|
|
|
2016-03-31 21:49:30 +02:00
|
|
|
if (insert_mode) {
|
2016-07-12 17:07:17 +02:00
|
|
|
cursor_pos.y += (get_row_height() - 3);
|
2016-05-09 20:21:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (draw_caret) {
|
|
|
|
if (insert_mode) {
|
|
|
|
int char_w = cache.font->get_char_size(' ').width;
|
2016-07-12 17:07:17 +02:00
|
|
|
int caret_h = (block_caret) ? 4 : 1;
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(char_w, caret_h)), cache.caret_color);
|
2016-05-09 20:21:55 +02:00
|
|
|
} else {
|
2016-07-12 17:07:17 +02:00
|
|
|
int char_w = cache.font->get_char_size(' ').width;
|
|
|
|
int caret_w = (block_caret) ? char_w : 1;
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(cursor_pos, Size2i(caret_w, get_row_height())), cache.caret_color);
|
2016-05-09 20:21:55 +02:00
|
|
|
}
|
2016-03-31 21:49:30 +02:00
|
|
|
}
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-28 15:36:57 +01:00
|
|
|
if (line_length_guideline) {
|
2017-03-05 16:44:50 +01:00
|
|
|
int x = xmargin_beg + cache.font->get_char_size('0').width * line_length_guideline_col - cursor.x_ofs;
|
|
|
|
if (x > xmargin_beg && x < xmargin_end) {
|
|
|
|
VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(x, 0), Point2(x, cache.size.height), cache.line_length_guideline_color);
|
2017-01-28 15:36:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 11:05:42 +01:00
|
|
|
bool completion_below = false;
|
2014-12-17 02:31:57 +01:00
|
|
|
if (completion_active) {
|
|
|
|
// code completion box
|
|
|
|
Ref<StyleBox> csb = get_stylebox("completion");
|
|
|
|
int maxlines = get_constant("completion_lines");
|
2017-03-05 16:44:50 +01:00
|
|
|
int cmax_width = get_constant("completion_max_width") * cache.font->get_char_size('x').x;
|
2014-12-17 02:31:57 +01:00
|
|
|
int scrollw = get_constant("completion_scroll_width");
|
|
|
|
Color scrollc = get_color("completion_scroll_color");
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int lines = MIN(completion_options.size(), maxlines);
|
|
|
|
int w = 0;
|
|
|
|
int h = lines * get_row_height();
|
2014-12-17 02:31:57 +01:00
|
|
|
int nofs = cache.font->get_string_size(completion_base).width;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (completion_options.size() < 50) {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < completion_options.size(); i++) {
|
|
|
|
int w2 = MIN(cache.font->get_string_size(completion_options[i]).x, cmax_width);
|
|
|
|
if (w2 > w)
|
|
|
|
w = w2;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
w = cmax_width;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
int th = h + csb->get_minimum_size().y;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor_pos.y + get_row_height() + th > get_size().height) {
|
2017-06-04 00:25:13 +02:00
|
|
|
completion_rect.position.y = cursor_pos.y - th;
|
2014-12-17 02:31:57 +01:00
|
|
|
} else {
|
2017-06-04 00:25:13 +02:00
|
|
|
completion_rect.position.y = cursor_pos.y + get_row_height() + csb->get_offset().y;
|
2016-03-04 11:05:42 +01:00
|
|
|
completion_below = true;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor_pos.x - nofs + w + scrollw > get_size().width) {
|
2017-06-04 00:25:13 +02:00
|
|
|
completion_rect.position.x = get_size().width - w - scrollw;
|
2014-12-17 02:31:57 +01:00
|
|
|
} else {
|
2017-06-04 00:25:13 +02:00
|
|
|
completion_rect.position.x = cursor_pos.x - nofs;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_rect.size.width = w + 2;
|
|
|
|
completion_rect.size.height = h;
|
|
|
|
if (completion_options.size() <= maxlines)
|
|
|
|
scrollw = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
draw_style_box(csb, Rect2(completion_rect.position - csb->get_offset(), completion_rect.size + csb->get_minimum_size() + Size2(scrollw, 0)));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cache.completion_background_color.a > 0.01) {
|
2017-06-04 00:25:13 +02:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(completion_rect.position, completion_rect.size + Size2(scrollw, 0)), cache.completion_background_color);
|
2016-06-21 17:50:31 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
int line_from = CLAMP(completion_index - lines / 2, 0, completion_options.size() - lines);
|
2017-06-04 00:25:13 +02:00
|
|
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(completion_rect.position.x, completion_rect.position.y + (completion_index - line_from) * get_row_height()), Size2(completion_rect.size.width, get_row_height())), cache.completion_selected_color);
|
|
|
|
draw_rect(Rect2(completion_rect.position, Size2(nofs, completion_rect.size.height)), cache.completion_existing_color);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < lines; i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
int l = line_from + i;
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_CONTINUE(l < 0 || l >= completion_options.size());
|
2016-07-11 15:25:56 +02:00
|
|
|
Color text_color = cache.completion_font_color;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < color_regions.size(); j++) {
|
2014-12-18 04:56:33 +01:00
|
|
|
if (completion_options[l].begins_with(color_regions[j].begin_key)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
text_color = color_regions[j].color;
|
2014-12-18 04:56:33 +01:00
|
|
|
}
|
|
|
|
}
|
2017-06-04 00:25:13 +02:00
|
|
|
draw_string(cache.font, Point2(completion_rect.position.x, completion_rect.position.y + i * get_row_height() + cache.font->get_ascent()), completion_options[l], text_color, completion_rect.size.width);
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (scrollw) {
|
|
|
|
//draw a small scroll rectangle to show a position in the options
|
|
|
|
float r = maxlines / (float)completion_options.size();
|
|
|
|
float o = line_from / (float)completion_options.size();
|
2017-06-04 00:25:13 +02:00
|
|
|
draw_rect(Rect2(completion_rect.position.x + completion_rect.size.width, completion_rect.position.y + o * completion_rect.size.y, scrollw, completion_rect.size.y * r), scrollc);
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_line_ofs = line_from;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-04 11:05:42 +01:00
|
|
|
|
|
|
|
// check to see if the hint should be drawn
|
|
|
|
bool show_hint = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (completion_hint != "") {
|
2016-03-04 11:05:42 +01:00
|
|
|
if (completion_active) {
|
|
|
|
if (completion_below && !callhint_below) {
|
|
|
|
show_hint = true;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (!completion_below && callhint_below) {
|
2016-03-04 11:05:42 +01:00
|
|
|
show_hint = true;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
} else {
|
2016-03-04 11:05:42 +01:00
|
|
|
show_hint = true;
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-04 11:05:42 +01:00
|
|
|
if (show_hint) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Ref<StyleBox> sb = get_stylebox("panel", "TooltipPanel");
|
2014-12-17 02:31:57 +01:00
|
|
|
Ref<Font> font = cache.font;
|
2017-03-05 16:44:50 +01:00
|
|
|
Color font_color = get_color("font_color", "TooltipLabel");
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int max_w = 0;
|
2014-12-17 02:31:57 +01:00
|
|
|
int sc = completion_hint.get_slice_count("\n");
|
2017-03-05 16:44:50 +01:00
|
|
|
int offset = 0;
|
|
|
|
int spacing = 0;
|
|
|
|
for (int i = 0; i < sc; i++) {
|
|
|
|
|
|
|
|
String l = completion_hint.get_slice("\n", i);
|
|
|
|
int len = font->get_string_size(l).x;
|
|
|
|
max_w = MAX(len, max_w);
|
|
|
|
if (i == 0) {
|
|
|
|
offset = font->get_string_size(l.substr(0, l.find(String::chr(0xFFFF)))).x;
|
2014-12-17 02:31:57 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
spacing += cache.line_spacing;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Size2 size = Size2(max_w, sc * font->get_height() + spacing);
|
|
|
|
Size2 minsize = size + sb->get_minimum_size();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (completion_hint_offset == -0xFFFF) {
|
|
|
|
completion_hint_offset = cursor_pos.x - offset;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Point2 hint_ofs = Vector2(completion_hint_offset, cursor_pos.y) + callhint_offset;
|
2016-03-04 11:05:42 +01:00
|
|
|
|
|
|
|
if (callhint_below) {
|
|
|
|
hint_ofs.y += get_row_height() + sb->get_offset().y;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else {
|
2016-03-04 11:05:42 +01:00
|
|
|
hint_ofs.y -= minsize.y + sb->get_offset().y;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
draw_style_box(sb, Rect2(hint_ofs, minsize));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
spacing = 0;
|
|
|
|
for (int i = 0; i < sc; i++) {
|
|
|
|
int begin = 0;
|
|
|
|
int end = 0;
|
|
|
|
String l = completion_hint.get_slice("\n", i);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (l.find(String::chr(0xFFFF)) != -1) {
|
|
|
|
begin = font->get_string_size(l.substr(0, l.find(String::chr(0xFFFF)))).x;
|
|
|
|
end = font->get_string_size(l.substr(0, l.rfind(String::chr(0xFFFF)))).x;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
draw_string(font, hint_ofs + sb->get_offset() + Vector2(0, font->get_ascent() + font->get_height() * i + spacing), l.replace(String::chr(0xFFFF), ""), font_color);
|
|
|
|
if (end > 0) {
|
|
|
|
Vector2 b = hint_ofs + sb->get_offset() + Vector2(begin, font->get_height() + font->get_height() * i + spacing - 1);
|
|
|
|
draw_line(b, b + Vector2(end - begin, 0), font_color);
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
spacing += cache.line_spacing;
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_FOCUS_ENTER: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-20 21:29:58 +02:00
|
|
|
if (!caret_blink_enabled) {
|
|
|
|
draw_caret = true;
|
|
|
|
}
|
2014-12-17 02:31:57 +01:00
|
|
|
if (OS::get_singleton()->has_virtual_keyboard())
|
2017-03-05 16:44:50 +01:00
|
|
|
OS::get_singleton()->show_virtual_keyboard(get_text(), get_global_rect());
|
2016-10-10 13:21:37 +02:00
|
|
|
if (raised_from_completion) {
|
|
|
|
VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 1);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_FOCUS_EXIT: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
if (OS::get_singleton()->has_virtual_keyboard())
|
|
|
|
OS::get_singleton()->hide_virtual_keyboard();
|
2016-10-10 13:21:37 +02:00
|
|
|
if (raised_from_completion) {
|
|
|
|
VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 0);
|
|
|
|
}
|
2014-12-17 02:31:57 +01:00
|
|
|
} break;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2014-04-27 12:34:37 +02:00
|
|
|
void TextEdit::_consume_pair_symbol(CharType ch) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
int cursor_position_to_move = cursor_get_column() + 1;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
CharType ch_single[2] = { ch, 0 };
|
|
|
|
CharType ch_single_pair[2] = { _get_right_pair_symbol(ch), 0 };
|
|
|
|
CharType ch_pair[3] = { ch, _get_right_pair_symbol(ch), 0 };
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (is_selection_active()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int new_column, new_line;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-04-06 08:36:29 +02:00
|
|
|
begin_complex_operation();
|
2015-01-02 19:08:40 +01:00
|
|
|
_insert_text(get_selection_from_line(), get_selection_from_column(),
|
2017-03-05 16:44:50 +01:00
|
|
|
ch_single,
|
|
|
|
&new_line, &new_column);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
int to_col_offset = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (get_selection_from_line() == get_selection_to_line())
|
2015-01-02 19:08:40 +01:00
|
|
|
to_col_offset = 1;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
_insert_text(get_selection_to_line(),
|
2017-03-05 16:44:50 +01:00
|
|
|
get_selection_to_column() + to_col_offset,
|
|
|
|
ch_single_pair,
|
|
|
|
&new_line, &new_column);
|
2016-04-06 08:36:29 +02:00
|
|
|
end_complex_operation();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
cursor_set_line(get_selection_to_line());
|
|
|
|
cursor_set_column(get_selection_to_column() + to_col_offset);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
deselect();
|
|
|
|
update();
|
|
|
|
return;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if ((ch == '\'' || ch == '"') &&
|
2015-01-02 19:08:40 +01:00
|
|
|
cursor_get_column() > 0 &&
|
2017-03-05 16:44:50 +01:00
|
|
|
_is_text_char(text[cursor.line][cursor_get_column() - 1])) {
|
2015-01-02 19:08:40 +01:00
|
|
|
insert_text_at_cursor(ch_single);
|
|
|
|
cursor_set_column(cursor_position_to_move);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor_get_column() < text[cursor.line].length()) {
|
|
|
|
if (_is_text_char(text[cursor.line][cursor_get_column()])) {
|
2015-01-02 19:08:40 +01:00
|
|
|
insert_text_at_cursor(ch_single);
|
|
|
|
cursor_set_column(cursor_position_to_move);
|
|
|
|
return;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (_is_pair_right_symbol(ch) &&
|
|
|
|
text[cursor.line][cursor_get_column()] == ch) {
|
2015-01-02 19:08:40 +01:00
|
|
|
cursor_set_column(cursor_position_to_move);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
insert_text_at_cursor(ch_pair);
|
|
|
|
cursor_set_column(cursor_position_to_move);
|
|
|
|
return;
|
2014-04-27 12:34:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::_consume_backspace_for_pair_symbol(int prev_line, int prev_column) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
bool remove_right_symbol = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.column < text[cursor.line].length() && cursor.column > 0) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
CharType left_char = text[cursor.line][cursor.column - 1];
|
|
|
|
CharType right_char = text[cursor.line][cursor.column];
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (right_char == _get_right_pair_symbol(left_char)) {
|
2015-01-02 19:08:40 +01:00
|
|
|
remove_right_symbol = true;
|
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (remove_right_symbol) {
|
|
|
|
_remove_text(prev_line, prev_column, cursor.line, cursor.column + 1);
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
_remove_text(prev_line, prev_column, cursor.line, cursor.column);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2014-04-27 12:34:37 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TextEdit::backspace_at_cursor() {
|
2015-01-02 19:08:40 +01:00
|
|
|
if (readonly)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.column == 0 && cursor.line == 0)
|
2015-01-02 19:08:40 +01:00
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int prev_line = cursor.column ? cursor.line : cursor.line - 1;
|
|
|
|
int prev_column = cursor.column ? (cursor.column - 1) : (text[cursor.line - 1].length());
|
|
|
|
if (auto_brace_completion_enabled &&
|
2015-01-02 19:08:40 +01:00
|
|
|
cursor.column > 0 &&
|
|
|
|
_is_pair_left_symbol(text[cursor.line][cursor.column - 1])) {
|
|
|
|
_consume_backspace_for_pair_symbol(prev_line, prev_column);
|
|
|
|
} else {
|
2017-04-17 15:24:30 +02:00
|
|
|
// handle space indentation
|
|
|
|
if (cursor.column - indent_size >= 0 && indent_using_spaces) {
|
|
|
|
|
|
|
|
// if there is enough spaces to count as a tab
|
|
|
|
bool unindent = true;
|
|
|
|
for (int i = 1; i <= indent_size; i++) {
|
|
|
|
if (text[cursor.line][cursor.column - i] != ' ') {
|
|
|
|
unindent = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// and it is before the first character
|
|
|
|
int i = 0;
|
|
|
|
while (i < cursor.column && i < text[cursor.line].length()) {
|
|
|
|
if (text[cursor.line][i] != ' ' && text[cursor.line][i] != '\t') {
|
|
|
|
unindent = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// then we can remove it as a single character.
|
|
|
|
if (unindent) {
|
|
|
|
_remove_text(cursor.line, cursor.column - indent_size, cursor.line, cursor.column);
|
|
|
|
prev_column = cursor.column - indent_size;
|
|
|
|
} else {
|
|
|
|
_remove_text(prev_line, prev_column, cursor.line, cursor.column);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_remove_text(prev_line, prev_column, cursor.line, cursor.column);
|
|
|
|
}
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
cursor_set_line(prev_line);
|
|
|
|
cursor_set_column(prev_column);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-04-06 17:37:03 +02:00
|
|
|
void TextEdit::indent_selection_right() {
|
|
|
|
|
|
|
|
if (!is_selection_active()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
begin_complex_operation();
|
|
|
|
int start_line = get_selection_from_line();
|
|
|
|
int end_line = get_selection_to_line();
|
|
|
|
|
|
|
|
// ignore if the cursor is not past the first column
|
|
|
|
if (get_selection_to_column() == 0) {
|
|
|
|
end_line--;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = start_line; i <= end_line; i++) {
|
|
|
|
String line_text = get_line(i);
|
2017-04-17 15:24:30 +02:00
|
|
|
if (indent_using_spaces) {
|
|
|
|
line_text = space_indent + line_text;
|
|
|
|
} else {
|
|
|
|
line_text = '\t' + line_text;
|
|
|
|
}
|
2016-04-06 17:37:03 +02:00
|
|
|
set_line(i, line_text);
|
|
|
|
}
|
|
|
|
|
|
|
|
// fix selection being off by one on the last line
|
|
|
|
selection.to_column++;
|
|
|
|
end_complex_operation();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::indent_selection_left() {
|
|
|
|
|
|
|
|
if (!is_selection_active()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
begin_complex_operation();
|
|
|
|
int start_line = get_selection_from_line();
|
|
|
|
int end_line = get_selection_to_line();
|
|
|
|
|
|
|
|
// ignore if the cursor is not past the first column
|
|
|
|
if (get_selection_to_column() == 0) {
|
|
|
|
end_line--;
|
|
|
|
}
|
|
|
|
String last_line_text = get_line(end_line);
|
|
|
|
|
|
|
|
for (int i = start_line; i <= end_line; i++) {
|
|
|
|
String line_text = get_line(i);
|
|
|
|
|
|
|
|
if (line_text.begins_with("\t")) {
|
|
|
|
line_text = line_text.substr(1, line_text.length());
|
|
|
|
set_line(i, line_text);
|
2017-04-17 15:24:30 +02:00
|
|
|
} else if (line_text.begins_with(space_indent)) {
|
|
|
|
line_text = line_text.substr(indent_size, line_text.length());
|
2016-04-06 17:37:03 +02:00
|
|
|
set_line(i, line_text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// fix selection being off by one on the last line
|
|
|
|
if (last_line_text != get_line(end_line) && selection.to_column > 0) {
|
|
|
|
selection.to_column--;
|
|
|
|
}
|
|
|
|
end_complex_operation();
|
|
|
|
update();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float rows = p_mouse.y;
|
|
|
|
rows -= cache.style_normal->get_margin(MARGIN_TOP);
|
|
|
|
rows /= get_row_height();
|
|
|
|
int row = cursor.line_ofs + rows;
|
2015-11-07 13:39:03 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (row < 0)
|
|
|
|
row = 0;
|
2015-11-07 13:39:03 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int col = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (row >= text.size()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
row = text.size() - 1;
|
|
|
|
col = text[row].size();
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
col = p_mouse.x - (cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width);
|
|
|
|
col += cursor.x_ofs;
|
|
|
|
col = get_char_pos_for(col, get_line(row));
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_row = row;
|
|
|
|
r_col = col;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEventMouseButton> mb = p_gui_input;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (mb.is_valid()) {
|
2017-06-03 10:54:24 +02:00
|
|
|
if (completion_active && completion_rect.has_point(mb->get_position())) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!mb->is_pressed())
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (mb->get_button_index() == BUTTON_WHEEL_UP) {
|
|
|
|
if (completion_index > 0) {
|
|
|
|
completion_index--;
|
|
|
|
completion_current = completion_options[completion_index];
|
|
|
|
update();
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
|
|
|
if (mb->get_button_index() == BUTTON_WHEEL_DOWN) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (completion_index < completion_options.size() - 1) {
|
|
|
|
completion_index++;
|
|
|
|
completion_current = completion_options[completion_index];
|
|
|
|
update();
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (mb->get_button_index() == BUTTON_LEFT) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-06-04 00:25:13 +02:00
|
|
|
completion_index = CLAMP(completion_line_ofs + (mb->get_position().y - completion_rect.position.y) / get_row_height(), 0, completion_options.size() - 1);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
completion_current = completion_options[completion_index];
|
|
|
|
update();
|
|
|
|
if (mb->is_doubleclick())
|
|
|
|
_confirm_completion();
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
_cancel_completion();
|
|
|
|
_cancel_code_hint();
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (mb->is_pressed()) {
|
2017-02-21 23:45:31 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (mb->get_button_index() == BUTTON_WHEEL_UP && !mb->get_command()) {
|
|
|
|
v_scroll->set_value(v_scroll->get_value() - (3 * mb->get_factor()));
|
|
|
|
}
|
|
|
|
if (mb->get_button_index() == BUTTON_WHEEL_DOWN && !mb->get_command()) {
|
|
|
|
v_scroll->set_value(v_scroll->get_value() + (3 * mb->get_factor()));
|
|
|
|
}
|
|
|
|
if (mb->get_button_index() == BUTTON_WHEEL_LEFT) {
|
|
|
|
h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor()));
|
|
|
|
}
|
|
|
|
if (mb->get_button_index() == BUTTON_WHEEL_RIGHT) {
|
|
|
|
h_scroll->set_value(h_scroll->get_value() + (100 * mb->get_factor()));
|
|
|
|
}
|
|
|
|
if (mb->get_button_index() == BUTTON_LEFT) {
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
_reset_caret_blink_timer();
|
|
|
|
|
|
|
|
int row, col;
|
2017-06-03 10:54:24 +02:00
|
|
|
_get_mouse_pos(Point2i(mb->get_position().x, mb->get_position().y), row, col);
|
2016-05-09 20:21:55 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (mb->get_command() && highlighted_word != String()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
emit_signal("symbol_lookup", highlighted_word, row, col);
|
|
|
|
return;
|
|
|
|
}
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
// toggle breakpoint on gutter click
|
|
|
|
if (draw_breakpoint_gutter) {
|
|
|
|
int gutter = cache.style_normal->get_margin(MARGIN_LEFT);
|
2017-06-03 10:54:24 +02:00
|
|
|
if (mb->get_position().x > gutter && mb->get_position().x <= gutter + cache.breakpoint_gutter_width + 3) {
|
2017-05-20 17:38:03 +02:00
|
|
|
set_line_as_breakpoint(row, !is_line_set_as_breakpoint(row));
|
|
|
|
emit_signal("breakpoint_toggled", row);
|
2016-09-12 15:52:29 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
int prev_col = cursor.column;
|
|
|
|
int prev_line = cursor.line;
|
2016-05-26 15:17:14 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
cursor_set_line(row);
|
|
|
|
cursor_set_column(col);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (mb->get_shift() && (cursor.column != prev_col || cursor.line != prev_line)) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!selection.active) {
|
|
|
|
selection.active = true;
|
|
|
|
selection.selecting_mode = Selection::MODE_POINTER;
|
|
|
|
selection.from_column = prev_col;
|
|
|
|
selection.from_line = prev_line;
|
|
|
|
selection.to_column = cursor.column;
|
|
|
|
selection.to_line = cursor.line;
|
|
|
|
|
|
|
|
if (selection.from_line > selection.to_line || (selection.from_line == selection.to_line && selection.from_column > selection.to_column)) {
|
|
|
|
SWAP(selection.from_column, selection.to_column);
|
|
|
|
SWAP(selection.from_line, selection.to_line);
|
|
|
|
selection.shiftclick_left = false;
|
|
|
|
} else {
|
|
|
|
selection.shiftclick_left = true;
|
|
|
|
}
|
|
|
|
selection.selecting_line = prev_line;
|
|
|
|
selection.selecting_column = prev_col;
|
|
|
|
update();
|
|
|
|
} else {
|
2015-01-02 19:08:40 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (cursor.line < selection.selecting_line || (cursor.line == selection.selecting_line && cursor.column < selection.selecting_column)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (selection.shiftclick_left) {
|
2017-03-05 16:44:50 +01:00
|
|
|
SWAP(selection.from_column, selection.to_column);
|
|
|
|
SWAP(selection.from_line, selection.to_line);
|
2017-05-20 17:38:03 +02:00
|
|
|
selection.shiftclick_left = !selection.shiftclick_left;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
selection.from_column = cursor.column;
|
|
|
|
selection.from_line = cursor.line;
|
2015-08-13 00:34:07 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} else if (cursor.line > selection.selecting_line || (cursor.line == selection.selecting_line && cursor.column > selection.selecting_column)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!selection.shiftclick_left) {
|
|
|
|
SWAP(selection.from_column, selection.to_column);
|
|
|
|
SWAP(selection.from_line, selection.to_line);
|
|
|
|
selection.shiftclick_left = !selection.shiftclick_left;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
selection.to_column = cursor.column;
|
|
|
|
selection.to_line = cursor.line;
|
2015-08-13 00:34:07 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} else {
|
|
|
|
selection.active = false;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
update();
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
//if sel active and dblick last time < something
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
//else
|
|
|
|
selection.active = false;
|
|
|
|
selection.selecting_mode = Selection::MODE_POINTER;
|
|
|
|
selection.selecting_line = row;
|
|
|
|
selection.selecting_column = col;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!mb->is_doubleclick() && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < 600 && cursor.line == prev_line) {
|
|
|
|
//tripleclick select line
|
|
|
|
select(cursor.line, 0, cursor.line, text[cursor.line].length());
|
|
|
|
selection.selecting_column = 0;
|
|
|
|
last_dblclk = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} else if (mb->is_doubleclick() && text[cursor.line].length()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
//doubleclick select world
|
|
|
|
String s = text[cursor.line];
|
|
|
|
int beg = CLAMP(cursor.column, 0, s.length());
|
|
|
|
int end = beg;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (s[beg] > 32 || beg == s.length()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this
|
2015-08-13 00:34:07 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
while (beg > 0 && s[beg - 1] > 32 && (symbol == _is_symbol(s[beg - 1]))) {
|
|
|
|
beg--;
|
|
|
|
}
|
|
|
|
while (end < s.length() && s[end + 1] > 32 && (symbol == _is_symbol(s[end + 1]))) {
|
|
|
|
end++;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (end < s.length())
|
|
|
|
end += 1;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
select(cursor.line, beg, cursor.line, end);
|
2016-05-17 01:25:17 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
selection.selecting_column = beg;
|
|
|
|
}
|
2016-05-17 01:25:17 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
last_dblclk = OS::get_singleton()->get_ticks_msec();
|
2016-05-17 01:25:17 +02:00
|
|
|
}
|
2015-12-09 19:56:41 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
update();
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (mb->get_button_index() == BUTTON_RIGHT && context_menu_enabled) {
|
|
|
|
|
|
|
|
menu->set_position(get_global_transform().xform(get_local_mouse_pos()));
|
|
|
|
menu->set_size(Vector2(1, 1));
|
|
|
|
menu->popup();
|
|
|
|
grab_focus();
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (mb->get_button_index() == BUTTON_LEFT)
|
|
|
|
click_select_held->stop();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
// notify to show soft keyboard
|
|
|
|
notification(NOTIFICATION_FOCUS_ENTER);
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEventMouseMotion> mm = p_gui_input;
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (mm.is_valid()) {
|
|
|
|
|
|
|
|
if (select_identifiers_enabled) {
|
|
|
|
if (mm->get_command() && mm->get_button_mask() == 0) {
|
|
|
|
|
2017-06-03 10:54:24 +02:00
|
|
|
String new_word = get_word_at_pos(mm->get_position());
|
2017-05-20 17:38:03 +02:00
|
|
|
if (new_word != highlighted_word) {
|
|
|
|
highlighted_word = new_word;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (highlighted_word != String()) {
|
|
|
|
highlighted_word = String();
|
|
|
|
update();
|
2016-09-12 15:52:29 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (mm->get_button_mask() & BUTTON_MASK_LEFT && get_viewport()->gui_get_drag_data() == Variant()) { //ignore if dragging
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (selection.selecting_mode != Selection::MODE_NONE) {
|
2015-12-09 19:56:41 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
_reset_caret_blink_timer();
|
2016-05-09 20:21:55 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
int row, col;
|
2017-06-03 10:54:24 +02:00
|
|
|
_get_mouse_pos(mm->get_position(), row, col);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
select(selection.selecting_line, selection.selecting_column, row, col);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
cursor_set_line(row);
|
|
|
|
cursor_set_column(col);
|
|
|
|
update();
|
2015-12-09 19:56:41 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
click_select_held->start();
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEventKey> k = p_gui_input;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k.is_valid()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
k = k->duplicate(); //it will be modified later on
|
2016-09-12 15:52:29 +02:00
|
|
|
|
|
|
|
#ifdef OSX_ENABLED
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_scancode() == KEY_META) {
|
2016-09-12 15:52:29 +02:00
|
|
|
#else
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_scancode() == KEY_CONTROL) {
|
2016-09-12 15:52:29 +02:00
|
|
|
|
|
|
|
#endif
|
2017-05-20 17:38:03 +02:00
|
|
|
if (select_identifiers_enabled) {
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->is_pressed()) {
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
highlighted_word = get_word_at_pos(get_local_mouse_pos());
|
|
|
|
update();
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} else {
|
|
|
|
highlighted_word = String();
|
|
|
|
update();
|
2016-09-12 15:52:29 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!k->is_pressed())
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (completion_active) {
|
|
|
|
if (readonly)
|
|
|
|
return;
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
bool valid = true;
|
|
|
|
if (k->get_command() || k->get_metakey())
|
|
|
|
valid = false;
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (valid) {
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!k->get_alt()) {
|
|
|
|
if (k->get_scancode() == KEY_UP) {
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (completion_index > 0) {
|
|
|
|
completion_index--;
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_current = completion_options[completion_index];
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_scancode() == KEY_DOWN) {
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (completion_index < completion_options.size() - 1) {
|
|
|
|
completion_index++;
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_current = completion_options[completion_index];
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_scancode() == KEY_PAGEUP) {
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
completion_index -= get_constant("completion_lines");
|
|
|
|
if (completion_index < 0)
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_index = 0;
|
2017-05-20 17:38:03 +02:00
|
|
|
completion_current = completion_options[completion_index];
|
|
|
|
update();
|
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_scancode() == KEY_PAGEDOWN) {
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
completion_index += get_constant("completion_lines");
|
|
|
|
if (completion_index >= completion_options.size())
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_index = completion_options.size() - 1;
|
2017-05-20 17:38:03 +02:00
|
|
|
completion_current = completion_options[completion_index];
|
|
|
|
update();
|
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_scancode() == KEY_HOME && completion_index > 0) {
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
completion_index = 0;
|
|
|
|
completion_current = completion_options[completion_index];
|
|
|
|
update();
|
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_scancode() == KEY_END && completion_index < completion_options.size() - 1) {
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
completion_index = completion_options.size() - 1;
|
|
|
|
completion_current = completion_options[completion_index];
|
|
|
|
update();
|
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_scancode() == KEY_DOWN) {
|
2016-05-09 20:21:55 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (completion_index < completion_options.size() - 1) {
|
|
|
|
completion_index++;
|
|
|
|
completion_current = completion_options[completion_index];
|
|
|
|
update();
|
2015-01-05 02:39:21 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
2015-01-05 02:39:21 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_scancode() == KEY_ENTER || k->get_scancode() == KEY_RETURN || k->get_scancode() == KEY_TAB) {
|
|
|
|
|
|
|
|
_confirm_completion();
|
|
|
|
accept_event();
|
|
|
|
return;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_scancode() == KEY_BACKSPACE) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-05-09 20:21:55 +02:00
|
|
|
_reset_caret_blink_timer();
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
backspace_at_cursor();
|
|
|
|
_update_completion_candidates();
|
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
2016-04-03 16:21:16 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_scancode() == KEY_SHIFT) {
|
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-04-03 16:21:16 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_unicode() > 32) {
|
2016-04-03 16:21:16 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
_reset_caret_blink_timer();
|
2016-04-03 16:21:16 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
const CharType chr[2] = { (CharType)k->get_unicode(), 0 };
|
|
|
|
if (auto_brace_completion_enabled && _is_pair_symbol(chr[0])) {
|
|
|
|
_consume_pair_symbol(chr[0]);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// remove the old character if in insert mode
|
|
|
|
if (insert_mode) {
|
|
|
|
begin_complex_operation();
|
|
|
|
|
|
|
|
// make sure we don't try and remove empty space
|
|
|
|
if (cursor.column < get_line(cursor.line).length()) {
|
|
|
|
_remove_text(cursor.line, cursor.column, cursor.line, cursor.column + 1);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
_insert_text_at_cursor(chr);
|
|
|
|
|
|
|
|
if (insert_mode) {
|
|
|
|
end_complex_operation();
|
|
|
|
}
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
_update_completion_candidates();
|
|
|
|
accept_event();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
_cancel_completion();
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
/* TEST CONTROL FIRST!! */
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
// some remaps for duplicate functions..
|
|
|
|
if (k->get_command() && !k->get_shift() && !k->get_alt() && !k->get_metakey() && k->get_scancode() == KEY_INSERT) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
k->set_scancode(KEY_C);
|
|
|
|
}
|
|
|
|
if (!k->get_command() && k->get_shift() && !k->get_alt() && !k->get_metakey() && k->get_scancode() == KEY_INSERT) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
k->set_scancode(KEY_V);
|
|
|
|
k->set_command(true);
|
|
|
|
k->set_shift(false);
|
|
|
|
}
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!k->get_command()) {
|
|
|
|
_reset_caret_blink_timer();
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
// save here for insert mode, just in case it is cleared in the following section
|
|
|
|
bool had_selection = selection.active;
|
2015-01-02 19:08:40 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
// stuff to do when selection is active..
|
|
|
|
if (selection.active) {
|
2015-01-02 19:08:40 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (readonly)
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
bool clear = false;
|
|
|
|
bool unselect = false;
|
|
|
|
bool dobreak = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
switch (k->get_scancode()) {
|
|
|
|
|
|
|
|
case KEY_TAB: {
|
|
|
|
if (k->get_shift()) {
|
|
|
|
indent_selection_left();
|
|
|
|
} else {
|
|
|
|
indent_selection_right();
|
|
|
|
}
|
|
|
|
dobreak = true;
|
|
|
|
accept_event();
|
|
|
|
} break;
|
|
|
|
case KEY_X:
|
|
|
|
case KEY_C:
|
|
|
|
//special keys often used with control, wait...
|
|
|
|
clear = (!k->get_command() || k->get_shift() || k->get_alt());
|
|
|
|
break;
|
|
|
|
case KEY_DELETE:
|
|
|
|
if (!k->get_shift()) {
|
2015-01-02 19:08:40 +01:00
|
|
|
accept_event();
|
2017-03-05 16:44:50 +01:00
|
|
|
clear = true;
|
|
|
|
dobreak = true;
|
2017-05-20 17:38:03 +02:00
|
|
|
} else if (k->get_command() || k->get_alt()) {
|
|
|
|
dobreak = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case KEY_BACKSPACE:
|
|
|
|
accept_event();
|
|
|
|
clear = true;
|
|
|
|
dobreak = true;
|
|
|
|
break;
|
|
|
|
case KEY_LEFT:
|
|
|
|
case KEY_RIGHT:
|
|
|
|
case KEY_UP:
|
|
|
|
case KEY_DOWN:
|
|
|
|
case KEY_PAGEUP:
|
|
|
|
case KEY_PAGEDOWN:
|
|
|
|
case KEY_HOME:
|
|
|
|
case KEY_END:
|
|
|
|
// ignore arrows if any modifiers are held (shift = selecting, others may be used for editor hotkeys)
|
|
|
|
if (k->get_command() || k->get_shift() || k->get_alt())
|
2015-01-02 19:08:40 +01:00
|
|
|
break;
|
2017-05-20 17:38:03 +02:00
|
|
|
unselect = true;
|
|
|
|
break;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
default:
|
|
|
|
if (k->get_unicode() >= 32 && !k->get_command() && !k->get_alt() && !k->get_metakey())
|
|
|
|
clear = true;
|
|
|
|
if (auto_brace_completion_enabled && _is_pair_left_symbol(k->get_unicode()))
|
|
|
|
clear = false;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (unselect) {
|
|
|
|
selection.active = false;
|
|
|
|
selection.selecting_mode = Selection::MODE_NONE;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
if (clear) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!dobreak) {
|
|
|
|
begin_complex_operation();
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
selection.active = false;
|
|
|
|
update();
|
|
|
|
_remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
|
|
|
|
cursor_set_line(selection.from_line);
|
|
|
|
cursor_set_column(selection.from_column);
|
|
|
|
update();
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
if (dobreak)
|
|
|
|
return;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
selection.selecting_text = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
bool scancode_handled = true;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
// special scancode test...
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
switch (k->get_scancode()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
case KEY_ENTER:
|
|
|
|
case KEY_RETURN: {
|
2015-01-02 19:08:40 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (readonly)
|
|
|
|
break;
|
2015-01-02 19:08:40 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
String ins = "\n";
|
|
|
|
|
|
|
|
//keep indentation
|
|
|
|
int space_count = 0;
|
|
|
|
for (int i = 0; i < text[cursor.line].length(); i++) {
|
|
|
|
if (text[cursor.line][i] == '\t') {
|
|
|
|
if (indent_using_spaces) {
|
|
|
|
ins += space_indent;
|
|
|
|
} else {
|
|
|
|
ins += "\t";
|
|
|
|
}
|
|
|
|
space_count = 0;
|
|
|
|
} else if (text[cursor.line][i] == ' ') {
|
|
|
|
space_count++;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (space_count == indent_size) {
|
2017-04-17 15:24:30 +02:00
|
|
|
if (indent_using_spaces) {
|
|
|
|
ins += space_indent;
|
|
|
|
} else {
|
|
|
|
ins += "\t";
|
|
|
|
}
|
|
|
|
space_count = 0;
|
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
} else {
|
|
|
|
break;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
|
|
|
if (auto_indent) {
|
|
|
|
// indent once again if previous line will end with ':'
|
|
|
|
// (i.e. colon precedes current cursor position)
|
|
|
|
if (cursor.column > 0 && text[cursor.line][cursor.column - 1] == ':') {
|
|
|
|
if (indent_using_spaces) {
|
|
|
|
ins += space_indent;
|
|
|
|
} else {
|
|
|
|
ins += "\t";
|
2015-11-29 17:02:35 +01:00
|
|
|
}
|
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
2016-03-04 20:10:31 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
bool first_line = false;
|
|
|
|
if (k->get_command()) {
|
|
|
|
if (k->get_shift()) {
|
|
|
|
if (cursor.line > 0) {
|
|
|
|
cursor_set_line(cursor.line - 1);
|
2016-03-04 20:10:31 +01:00
|
|
|
cursor_set_column(text[cursor.line].length());
|
2017-05-20 17:38:03 +02:00
|
|
|
} else {
|
|
|
|
cursor_set_column(0);
|
|
|
|
first_line = true;
|
2016-03-04 20:10:31 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
} else {
|
|
|
|
cursor_set_column(text[cursor.line].length());
|
2016-03-04 20:10:31 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
_insert_text_at_cursor(ins);
|
|
|
|
_push_current_op();
|
2016-03-04 20:10:31 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (first_line) {
|
|
|
|
cursor_set_line(0);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
|
|
|
case KEY_ESCAPE: {
|
|
|
|
if (completion_hint != "") {
|
|
|
|
completion_hint = "";
|
|
|
|
update();
|
|
|
|
} else {
|
|
|
|
scancode_handled = false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case KEY_TAB: {
|
|
|
|
if (k->get_command()) break; // avoid tab when command
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (readonly)
|
|
|
|
break;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (selection.active) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} else {
|
|
|
|
if (k->get_shift()) {
|
|
|
|
|
|
|
|
//simple unindent
|
|
|
|
int cc = cursor.column;
|
|
|
|
if (cc > 0 && cc <= text[cursor.line].length()) {
|
|
|
|
if (text[cursor.line][cursor.column - 1] == '\t') {
|
|
|
|
backspace_at_cursor();
|
|
|
|
} else {
|
|
|
|
if (cursor.column - indent_size >= 0) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
bool unindent = true;
|
|
|
|
for (int i = 1; i <= indent_size; i++) {
|
|
|
|
if (text[cursor.line][cursor.column - i] != ' ') {
|
|
|
|
unindent = false;
|
|
|
|
break;
|
2017-04-17 15:24:30 +02:00
|
|
|
}
|
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
|
|
|
|
if (unindent) {
|
|
|
|
_remove_text(cursor.line, cursor.column - indent_size, cursor.line, cursor.column);
|
|
|
|
cursor_set_column(cursor.column - indent_size);
|
|
|
|
}
|
2017-04-17 15:24:30 +02:00
|
|
|
}
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//simple indent
|
|
|
|
if (indent_using_spaces) {
|
|
|
|
_insert_text_at_cursor(space_indent);
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2017-05-20 17:38:03 +02:00
|
|
|
_insert_text_at_cursor("\t");
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
|
|
|
case KEY_BACKSPACE: {
|
|
|
|
if (readonly)
|
|
|
|
break;
|
2015-11-12 17:35:48 +01:00
|
|
|
|
|
|
|
#ifdef APPLE_STYLE_KEYS
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_alt()) {
|
2015-11-12 17:35:48 +01:00
|
|
|
#else
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_alt()) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
} else if (k->get_command()) {
|
2015-11-12 17:35:48 +01:00
|
|
|
#endif
|
2017-05-20 17:38:03 +02:00
|
|
|
int line = cursor.line;
|
|
|
|
int column = cursor.column;
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
bool prev_char = false;
|
|
|
|
bool only_whitespace = true;
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
while (only_whitespace && line > 0) {
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (column > 0) {
|
2017-05-20 17:38:03 +02:00
|
|
|
CharType c = text[line][column - 1];
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (c != '\t' && c != ' ') {
|
|
|
|
only_whitespace = false;
|
2015-11-12 17:35:48 +01:00
|
|
|
break;
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
2015-11-12 17:35:48 +01:00
|
|
|
|
|
|
|
column--;
|
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (only_whitespace) {
|
|
|
|
line--;
|
|
|
|
column = text[line].length();
|
|
|
|
}
|
|
|
|
}
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
while (column > 0) {
|
|
|
|
bool ischar = _is_text_char(text[line][column - 1]);
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (prev_char && !ischar)
|
|
|
|
break;
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
prev_char = ischar;
|
|
|
|
column--;
|
2016-01-07 21:38:38 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
|
|
|
|
_remove_text(line, column, cursor.line, cursor.column);
|
|
|
|
|
|
|
|
cursor_set_line(line);
|
|
|
|
cursor_set_column(column);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
backspace_at_cursor();
|
2016-01-07 21:38:38 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
|
|
|
case KEY_KP_4: {
|
|
|
|
if (k->get_unicode() != 0) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// numlock disabled. fallthrough to key_left
|
|
|
|
}
|
|
|
|
case KEY_LEFT: {
|
|
|
|
|
|
|
|
if (k->get_shift())
|
|
|
|
_pre_shift_selection();
|
2016-06-23 23:03:32 +02:00
|
|
|
#ifdef APPLE_STYLE_KEYS
|
2017-05-20 17:38:03 +02:00
|
|
|
else
|
2016-06-23 23:03:32 +02:00
|
|
|
#else
|
2017-05-20 17:38:03 +02:00
|
|
|
else if (!k->get_alt())
|
2016-06-23 23:03:32 +02:00
|
|
|
#endif
|
2017-05-20 17:38:03 +02:00
|
|
|
deselect();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifdef APPLE_STYLE_KEYS
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_command()) {
|
|
|
|
cursor_set_column(0);
|
|
|
|
} else if (k->get_alt()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#else
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_alt()) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
} else if (k->get_command()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
2017-05-20 17:38:03 +02:00
|
|
|
bool prev_char = false;
|
|
|
|
int cc = cursor.column;
|
|
|
|
while (cc > 0) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
bool ischar = _is_text_char(text[cursor.line][cc - 1]);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (prev_char && !ischar)
|
|
|
|
break;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
prev_char = ischar;
|
|
|
|
cc--;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
cursor_set_column(cc);
|
|
|
|
|
|
|
|
} else if (cursor.column == 0) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (cursor.line > 0) {
|
|
|
|
cursor_set_line(cursor.line - 1);
|
|
|
|
cursor_set_column(text[cursor.line].length());
|
2016-01-07 21:38:38 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
} else {
|
|
|
|
cursor_set_column(cursor_get_column() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k->get_shift())
|
|
|
|
_post_shift_selection();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case KEY_KP_6: {
|
|
|
|
if (k->get_unicode() != 0) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
2016-01-07 21:38:38 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
// numlock disabled. fallthrough to key_right
|
|
|
|
}
|
|
|
|
case KEY_RIGHT: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_pre_shift_selection();
|
2016-06-23 23:03:32 +02:00
|
|
|
#ifdef APPLE_STYLE_KEYS
|
2017-05-20 17:38:03 +02:00
|
|
|
else
|
2016-06-23 23:03:32 +02:00
|
|
|
#else
|
2017-05-20 17:38:03 +02:00
|
|
|
else if (!k->get_alt())
|
2016-06-23 23:03:32 +02:00
|
|
|
#endif
|
2017-05-20 17:38:03 +02:00
|
|
|
deselect();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifdef APPLE_STYLE_KEYS
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_command()) {
|
|
|
|
cursor_set_column(text[cursor.line].length());
|
|
|
|
} else if (k->get_alt()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
#else
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_alt()) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
} else if (k->get_command()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
2017-05-20 17:38:03 +02:00
|
|
|
bool prev_char = false;
|
|
|
|
int cc = cursor.column;
|
|
|
|
while (cc < text[cursor.line].length()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
bool ischar = _is_text_char(text[cursor.line][cc]);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (prev_char && !ischar)
|
|
|
|
break;
|
|
|
|
prev_char = ischar;
|
|
|
|
cc++;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
cursor_set_column(cc);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} else if (cursor.column == text[cursor.line].length()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (cursor.line < text.size() - 1) {
|
|
|
|
cursor_set_line(cursor.line + 1);
|
|
|
|
cursor_set_column(0);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
} else {
|
|
|
|
cursor_set_column(cursor_get_column() + 1);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_post_shift_selection();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
|
|
|
case KEY_KP_8: {
|
|
|
|
if (k->get_unicode() != 0) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
2016-01-07 21:38:38 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
// numlock disabled. fallthrough to key_up
|
|
|
|
}
|
|
|
|
case KEY_UP: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_pre_shift_selection();
|
|
|
|
if (k->get_alt()) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
}
|
2016-04-27 19:32:14 +02:00
|
|
|
#ifndef APPLE_STYLE_KEYS
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_command()) {
|
|
|
|
_scroll_lines_up();
|
|
|
|
break;
|
|
|
|
}
|
2016-04-27 19:32:14 +02:00
|
|
|
#else
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_command() && k->get_alt()) {
|
|
|
|
_scroll_lines_up();
|
|
|
|
break;
|
|
|
|
}
|
2016-04-27 19:32:14 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_command())
|
|
|
|
cursor_set_line(0);
|
|
|
|
else
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
2017-05-20 17:38:03 +02:00
|
|
|
cursor_set_line(cursor_get_line() - 1);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_post_shift_selection();
|
|
|
|
_cancel_code_hint();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
|
|
|
case KEY_KP_2: {
|
|
|
|
if (k->get_unicode() != 0) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
2016-01-07 21:38:38 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
// numlock disabled. fallthrough to key_down
|
|
|
|
}
|
|
|
|
case KEY_DOWN: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_pre_shift_selection();
|
|
|
|
if (k->get_alt()) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
}
|
2016-04-27 19:32:14 +02:00
|
|
|
#ifndef APPLE_STYLE_KEYS
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_command()) {
|
|
|
|
_scroll_lines_down();
|
|
|
|
break;
|
|
|
|
}
|
2016-04-27 19:32:14 +02:00
|
|
|
#else
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_command() && k->get_alt()) {
|
|
|
|
_scroll_lines_down();
|
|
|
|
break;
|
|
|
|
}
|
2016-04-27 19:32:14 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_command())
|
|
|
|
cursor_set_line(text.size() - 1);
|
|
|
|
else
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
2017-05-20 17:38:03 +02:00
|
|
|
cursor_set_line(cursor_get_line() + 1);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_post_shift_selection();
|
|
|
|
_cancel_code_hint();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
case KEY_DELETE: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (readonly)
|
|
|
|
break;
|
2016-03-15 13:03:38 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift() && !k->get_command() && !k->get_alt()) {
|
|
|
|
cut();
|
|
|
|
break;
|
|
|
|
}
|
2016-03-15 13:03:38 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
int curline_len = text[cursor.line].length();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (cursor.line == text.size() - 1 && cursor.column == curline_len)
|
|
|
|
break; //nothing to do
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
int next_line = cursor.column < curline_len ? cursor.line : cursor.line + 1;
|
|
|
|
int next_column;
|
2015-11-12 17:35:48 +01:00
|
|
|
|
|
|
|
#ifdef APPLE_STYLE_KEYS
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_alt()) {
|
2015-11-12 17:35:48 +01:00
|
|
|
#else
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_alt()) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
} else if (k->get_command()) {
|
2015-11-12 17:35:48 +01:00
|
|
|
#endif
|
2017-05-20 17:38:03 +02:00
|
|
|
int last_line = text.size() - 1;
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
int line = cursor.line;
|
|
|
|
int column = cursor.column;
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
bool prev_char = false;
|
|
|
|
bool only_whitespace = true;
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
while (only_whitespace && line < last_line) {
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
while (column < text[line].length()) {
|
|
|
|
CharType c = text[line][column];
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (c != '\t' && c != ' ') {
|
|
|
|
only_whitespace = false;
|
|
|
|
break;
|
2015-11-12 17:35:48 +01:00
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
column++;
|
2015-11-12 17:35:48 +01:00
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (only_whitespace) {
|
|
|
|
line++;
|
|
|
|
column = 0;
|
|
|
|
}
|
|
|
|
}
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
while (column < text[line].length()) {
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
bool ischar = _is_text_char(text[line][column]);
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (prev_char && !ischar)
|
|
|
|
break;
|
|
|
|
prev_char = ischar;
|
|
|
|
column++;
|
2015-11-12 17:35:48 +01:00
|
|
|
}
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
next_line = line;
|
|
|
|
next_column = column;
|
|
|
|
} else {
|
|
|
|
next_column = cursor.column < curline_len ? (cursor.column + 1) : 0;
|
|
|
|
}
|
2015-11-12 17:35:48 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
_remove_text(cursor.line, cursor.column, next_line, next_column);
|
|
|
|
update();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case KEY_KP_7: {
|
|
|
|
if (k->get_unicode() != 0) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
2016-01-07 22:45:28 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
// numlock disabled. fallthrough to key_home
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifdef APPLE_STYLE_KEYS
|
2017-05-20 17:38:03 +02:00
|
|
|
case KEY_HOME: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_pre_shift_selection();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
cursor_set_line(0);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_post_shift_selection();
|
|
|
|
else if (k->get_command() || k->get_control())
|
|
|
|
deselect();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
#else
|
2017-05-20 17:38:03 +02:00
|
|
|
case KEY_HOME: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_pre_shift_selection();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_command()) {
|
|
|
|
cursor_set_line(0);
|
|
|
|
cursor_set_column(0);
|
|
|
|
} else {
|
|
|
|
// compute whitespace symbols seq length
|
|
|
|
int current_line_whitespace_len = 0;
|
|
|
|
while (current_line_whitespace_len < text[cursor.line].length()) {
|
|
|
|
CharType c = text[cursor.line][current_line_whitespace_len];
|
|
|
|
if (c != '\t' && c != ' ')
|
|
|
|
break;
|
|
|
|
current_line_whitespace_len++;
|
2017-02-03 08:01:41 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (cursor_get_column() == current_line_whitespace_len)
|
|
|
|
cursor_set_column(0);
|
|
|
|
else
|
|
|
|
cursor_set_column(current_line_whitespace_len);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_post_shift_selection();
|
|
|
|
else if (k->get_command() || k->get_control())
|
|
|
|
deselect();
|
|
|
|
_cancel_completion();
|
|
|
|
completion_hint = "";
|
|
|
|
|
|
|
|
} break;
|
2016-01-07 22:45:28 +01:00
|
|
|
#endif
|
2017-05-20 17:38:03 +02:00
|
|
|
case KEY_KP_1: {
|
|
|
|
if (k->get_unicode() != 0) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
2016-01-07 22:45:28 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
// numlock disabled. fallthrough to key_end
|
|
|
|
}
|
2016-01-07 22:45:28 +01:00
|
|
|
#ifdef APPLE_STYLE_KEYS
|
2017-05-20 17:38:03 +02:00
|
|
|
case KEY_END: {
|
2016-01-07 22:45:28 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_pre_shift_selection();
|
2016-01-07 22:45:28 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
cursor_set_line(text.size() - 1);
|
2016-01-07 22:45:28 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_post_shift_selection();
|
|
|
|
else if (k->get_command() || k->get_control())
|
|
|
|
deselect();
|
2016-01-07 22:45:28 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
2016-01-07 22:45:28 +01:00
|
|
|
#else
|
2017-05-20 17:38:03 +02:00
|
|
|
case KEY_END: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_pre_shift_selection();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_command())
|
|
|
|
cursor_set_line(text.size() - 1);
|
|
|
|
cursor_set_column(text[cursor.line].length());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_post_shift_selection();
|
|
|
|
else if (k->get_command() || k->get_control())
|
|
|
|
deselect();
|
2015-06-27 20:52:39 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
_cancel_completion();
|
|
|
|
completion_hint = "";
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
2017-05-20 17:38:03 +02:00
|
|
|
case KEY_KP_9: {
|
|
|
|
if (k->get_unicode() != 0) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
2016-01-07 22:45:28 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
// numlock disabled. fallthrough to key_pageup
|
|
|
|
}
|
|
|
|
case KEY_PAGEUP: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_pre_shift_selection();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
cursor_set_line(cursor_get_line() - get_visible_rows());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_post_shift_selection();
|
2015-06-27 20:52:39 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
_cancel_completion();
|
|
|
|
completion_hint = "";
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
|
|
|
case KEY_KP_3: {
|
|
|
|
if (k->get_unicode() != 0) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
2016-01-07 22:45:28 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
// numlock disabled. fallthrough to key_pageup
|
|
|
|
}
|
|
|
|
case KEY_PAGEDOWN: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_pre_shift_selection();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
cursor_set_line(cursor_get_line() + get_visible_rows());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
_post_shift_selection();
|
2015-06-27 20:52:39 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
_cancel_completion();
|
|
|
|
completion_hint = "";
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
|
|
|
case KEY_A: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!k->get_command() || k->get_shift() || k->get_alt()) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
select_all();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
|
|
|
case KEY_X: {
|
|
|
|
if (readonly) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!k->get_command() || k->get_shift() || k->get_alt()) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
cut();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
|
|
|
case KEY_C: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!k->get_command() || k->get_shift() || k->get_alt()) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
copy();
|
2016-03-15 13:02:38 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
|
|
|
case KEY_Z: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!k->get_command()) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_shift())
|
|
|
|
redo();
|
|
|
|
else
|
|
|
|
undo();
|
|
|
|
} break;
|
|
|
|
case KEY_V: {
|
|
|
|
if (readonly) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!k->get_command() || k->get_shift() || k->get_alt()) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
paste();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
|
|
|
case KEY_SPACE: {
|
2015-01-04 15:03:31 +01:00
|
|
|
#ifdef OSX_ENABLED
|
2017-05-20 17:38:03 +02:00
|
|
|
if (completion_enabled && k->get_metakey()) { //cmd-space is spotlight shortcut in OSX
|
2015-01-04 15:03:31 +01:00
|
|
|
#else
|
2017-05-20 17:38:03 +02:00
|
|
|
if (completion_enabled && k->get_command()) {
|
2015-01-04 15:03:31 +01:00
|
|
|
#endif
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
query_code_comple();
|
|
|
|
scancode_handled = true;
|
|
|
|
} else {
|
|
|
|
scancode_handled = false;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
} break;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
case KEY_U: {
|
|
|
|
if (!k->get_command() || k->get_shift()) {
|
|
|
|
scancode_handled = false;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (selection.active) {
|
|
|
|
int ini = selection.from_line;
|
|
|
|
int end = selection.to_line;
|
|
|
|
for (int i = ini; i <= end; i++) {
|
|
|
|
if (text[i][0] == '#')
|
|
|
|
_remove_text(i, 0, i, 1);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
} else {
|
|
|
|
if (text[cursor.line][0] == '#')
|
|
|
|
_remove_text(cursor.line, 0, cursor.line, 1);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
} break;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
default: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
scancode_handled = false;
|
|
|
|
} break;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (scancode_handled)
|
|
|
|
accept_event();
|
|
|
|
/*
|
|
|
|
if (!scancode_handled && !k->get_command() && !k->get_alt()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_unicode()>=32) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (readonly)
|
|
|
|
break;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
accept_event();
|
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-12-07 15:33:57 +01:00
|
|
|
*/
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_scancode() == KEY_INSERT) {
|
|
|
|
set_insert_mode(!insert_mode);
|
|
|
|
accept_event();
|
|
|
|
return;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (!scancode_handled && !k->get_command()) { //for german kbds
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (k->get_unicode() >= 32) {
|
2016-03-31 21:49:30 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (readonly)
|
|
|
|
return;
|
2016-03-31 21:49:30 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
// remove the old character if in insert mode and no selection
|
|
|
|
if (insert_mode && !had_selection) {
|
|
|
|
begin_complex_operation();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
// make sure we don't try and remove empty space
|
|
|
|
if (cursor.column < get_line(cursor.line).length()) {
|
|
|
|
_remove_text(cursor.line, cursor.column, cursor.line, cursor.column + 1);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
const CharType chr[2] = { (CharType)k->get_unicode(), 0 };
|
2016-04-05 14:52:18 +02:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (completion_hint != "" && k->get_unicode() == ')') {
|
|
|
|
completion_hint = "";
|
|
|
|
}
|
|
|
|
if (auto_brace_completion_enabled && _is_pair_symbol(chr[0])) {
|
|
|
|
_consume_pair_symbol(chr[0]);
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2017-05-20 17:38:03 +02:00
|
|
|
_insert_text_at_cursor(chr);
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
if (insert_mode && !had_selection) {
|
|
|
|
end_complex_operation();
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
|
|
|
|
if (selection.active != had_selection) {
|
|
|
|
end_complex_operation();
|
|
|
|
}
|
|
|
|
accept_event();
|
|
|
|
} else {
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
return;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::_pre_shift_selection() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!selection.active || selection.selecting_mode == Selection::MODE_NONE) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selection.selecting_line = cursor.line;
|
|
|
|
selection.selecting_column = cursor.column;
|
|
|
|
selection.active = true;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2015-08-13 00:34:07 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selection.selecting_mode = Selection::MODE_SHIFT;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::_post_shift_selection() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (selection.active && selection.selecting_mode == Selection::MODE_SHIFT) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
select(selection.selecting_line, selection.selecting_column, cursor.line, cursor.column);
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selection.selecting_text = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-04-27 19:32:14 +02:00
|
|
|
void TextEdit::_scroll_lines_up() {
|
|
|
|
// adjust the vertical scroll
|
|
|
|
if (get_v_scroll() > 0) {
|
|
|
|
set_v_scroll(get_v_scroll() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// adjust the cursor
|
|
|
|
if (cursor_get_line() >= (get_visible_rows() + get_v_scroll()) && !selection.active) {
|
|
|
|
cursor_set_line((get_visible_rows() + get_v_scroll()) - 1, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::_scroll_lines_down() {
|
|
|
|
// calculate the maximum vertical scroll position
|
|
|
|
int max_v_scroll = get_line_count() - 1;
|
|
|
|
if (!scroll_past_end_of_file_enabled) {
|
|
|
|
max_v_scroll -= get_visible_rows() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// adjust the vertical scroll
|
|
|
|
if (get_v_scroll() < max_v_scroll) {
|
|
|
|
set_v_scroll(get_v_scroll() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// adjust the cursor
|
|
|
|
if ((cursor_get_line()) <= get_v_scroll() - 1 && !selection.active) {
|
|
|
|
cursor_set_line(get_v_scroll(), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
/**** TEXT EDIT CORE API ****/
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, int &r_end_line, int &r_end_column) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
//save for undo...
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(p_line, text.size());
|
|
|
|
ERR_FAIL_COND(p_char < 0);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
/* STEP 1 add spaces if the char is greater than the end of the line */
|
2017-03-05 16:44:50 +01:00
|
|
|
while (p_char > text[p_line].length()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
text.set(p_line, text[p_line] + String::chr(' '));
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
/* STEP 2 separate dest string in pre and post text */
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String preinsert_text = text[p_line].substr(0, p_char);
|
|
|
|
String postinsert_text = text[p_line].substr(p_char, text[p_line].size());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
/* STEP 3 remove \r from source text and separate in substrings */
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
//buh bye \r and split
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector<String> substrings = p_text.replace("\r", "").split("\n");
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < substrings.size(); i++) {
|
2015-01-02 19:08:40 +01:00
|
|
|
//insert the substrings
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == 0) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
text.set(p_line, preinsert_text + substrings[i]);
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
text.insert(p_line + i, substrings[i]);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == substrings.size() - 1) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
text.set(p_line + i, text[p_line + i] + postinsert_text);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_end_line = p_line + substrings.size() - 1;
|
|
|
|
r_end_column = text[r_end_line].length() - postinsert_text.length();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!text_changed_dirty && !setting_text) {
|
|
|
|
if (is_inside_tree())
|
2017-03-05 16:44:50 +01:00
|
|
|
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
|
|
|
|
text_changed_dirty = true;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String TextEdit::_base_get_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_from_line, text.size(), String());
|
|
|
|
ERR_FAIL_INDEX_V(p_from_column, text[p_from_line].length() + 1, String());
|
|
|
|
ERR_FAIL_INDEX_V(p_to_line, text.size(), String());
|
|
|
|
ERR_FAIL_INDEX_V(p_to_column, text[p_to_line].length() + 1, String());
|
|
|
|
ERR_FAIL_COND_V(p_to_line < p_from_line, String()); // from > to
|
|
|
|
ERR_FAIL_COND_V(p_to_line == p_from_line && p_to_column < p_from_column, String()); // from > to
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
String ret;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = p_from_line; i <= p_to_line; i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int begin = (i == p_from_line) ? p_from_column : 0;
|
|
|
|
int end = (i == p_to_line) ? p_to_column : text[i].length();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i > p_from_line)
|
|
|
|
ret += "\n";
|
|
|
|
ret += text[i].substr(begin, end - begin);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return ret;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(p_from_line, text.size());
|
|
|
|
ERR_FAIL_INDEX(p_from_column, text[p_from_line].length() + 1);
|
|
|
|
ERR_FAIL_INDEX(p_to_line, text.size());
|
|
|
|
ERR_FAIL_INDEX(p_to_column, text[p_to_line].length() + 1);
|
|
|
|
ERR_FAIL_COND(p_to_line < p_from_line); // from > to
|
|
|
|
ERR_FAIL_COND(p_to_line == p_from_line && p_to_column < p_from_column); // from > to
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String pre_text = text[p_from_line].substr(0, p_from_column);
|
|
|
|
String post_text = text[p_to_line].substr(p_to_column, text[p_to_line].length());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = p_from_line; i < p_to_line; i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
text.remove(p_from_line + 1);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
text.set(p_from_line, pre_text + post_text);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!text_changed_dirty && !setting_text) {
|
|
|
|
if (is_inside_tree())
|
2017-03-05 16:44:50 +01:00
|
|
|
MessageQueue::get_singleton()->push_call(this, "_text_changed_emit");
|
|
|
|
text_changed_dirty = true;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r_end_line, int *r_end_column) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!setting_text)
|
|
|
|
idle_detect->start();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (undo_enabled) {
|
|
|
|
_clear_redo();
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int retline, retchar;
|
|
|
|
_base_insert_text(p_line, p_char, p_text, retline, retchar);
|
2015-01-02 19:08:40 +01:00
|
|
|
if (r_end_line)
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_end_line = retline;
|
2015-01-02 19:08:40 +01:00
|
|
|
if (r_end_column)
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_end_column = retchar;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!undo_enabled)
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
/* UNDO!! */
|
|
|
|
TextOperation op;
|
2017-03-05 16:44:50 +01:00
|
|
|
op.type = TextOperation::TYPE_INSERT;
|
|
|
|
op.from_line = p_line;
|
|
|
|
op.from_column = p_char;
|
|
|
|
op.to_line = retline;
|
|
|
|
op.to_column = retchar;
|
|
|
|
op.text = p_text;
|
|
|
|
op.version = ++version;
|
|
|
|
op.chain_forward = false;
|
|
|
|
op.chain_backward = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
//see if it shold just be set as current op
|
2017-03-05 16:44:50 +01:00
|
|
|
if (current_op.type != op.type) {
|
2016-03-13 21:08:12 +01:00
|
|
|
op.prev_version = get_version();
|
2015-01-02 19:08:40 +01:00
|
|
|
_push_current_op();
|
2017-03-05 16:44:50 +01:00
|
|
|
current_op = op;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return; //set as current op, return
|
|
|
|
}
|
|
|
|
//see if it can be merged
|
2017-03-05 16:44:50 +01:00
|
|
|
if (current_op.to_line != p_line || current_op.to_column != p_char) {
|
2016-03-13 21:08:12 +01:00
|
|
|
op.prev_version = get_version();
|
2015-01-02 19:08:40 +01:00
|
|
|
_push_current_op();
|
2017-03-05 16:44:50 +01:00
|
|
|
current_op = op;
|
2015-01-02 19:08:40 +01:00
|
|
|
return; //set as current op, return
|
|
|
|
}
|
|
|
|
//merge current op
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
current_op.text += p_text;
|
|
|
|
current_op.to_column = retchar;
|
|
|
|
current_op.to_line = retline;
|
|
|
|
current_op.version = op.version;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::_remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!setting_text)
|
|
|
|
idle_detect->start();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
String text;
|
|
|
|
if (undo_enabled) {
|
|
|
|
_clear_redo();
|
2017-03-05 16:44:50 +01:00
|
|
|
text = _base_get_text(p_from_line, p_from_column, p_to_line, p_to_column);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_base_remove_text(p_from_line, p_from_column, p_to_line, p_to_column);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!undo_enabled)
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
/* UNDO!! */
|
|
|
|
TextOperation op;
|
2017-03-05 16:44:50 +01:00
|
|
|
op.type = TextOperation::TYPE_REMOVE;
|
|
|
|
op.from_line = p_from_line;
|
|
|
|
op.from_column = p_from_column;
|
|
|
|
op.to_line = p_to_line;
|
|
|
|
op.to_column = p_to_column;
|
|
|
|
op.text = text;
|
|
|
|
op.version = ++version;
|
|
|
|
op.chain_forward = false;
|
|
|
|
op.chain_backward = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
//see if it shold just be set as current op
|
2017-03-05 16:44:50 +01:00
|
|
|
if (current_op.type != op.type) {
|
2016-03-13 21:08:12 +01:00
|
|
|
op.prev_version = get_version();
|
2015-01-02 19:08:40 +01:00
|
|
|
_push_current_op();
|
2017-03-05 16:44:50 +01:00
|
|
|
current_op = op;
|
2015-01-02 19:08:40 +01:00
|
|
|
return; //set as current op, return
|
|
|
|
}
|
|
|
|
//see if it can be merged
|
2017-03-05 16:44:50 +01:00
|
|
|
if (current_op.from_line == p_to_line && current_op.from_column == p_to_column) {
|
2015-01-02 19:08:40 +01:00
|
|
|
//basckace or similar
|
2017-03-05 16:44:50 +01:00
|
|
|
current_op.text = text + current_op.text;
|
|
|
|
current_op.from_line = p_from_line;
|
|
|
|
current_op.from_column = p_from_column;
|
2015-01-02 19:08:40 +01:00
|
|
|
return; //update current op
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (current_op.from_line == p_from_line && current_op.from_column == p_from_column) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
//current_op.text=text+current_op.text;
|
|
|
|
//current_op.from_line=p_from_line;
|
|
|
|
//current_op.from_column=p_from_column;
|
|
|
|
//return; //update current op
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-13 21:08:12 +01:00
|
|
|
op.prev_version = get_version();
|
2015-01-02 19:08:40 +01:00
|
|
|
_push_current_op();
|
2017-03-05 16:44:50 +01:00
|
|
|
current_op = op;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::_insert_text_at_cursor(const String &p_text) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int new_column, new_line;
|
|
|
|
_insert_text(cursor.line, cursor.column, p_text, &new_line, &new_column);
|
2015-01-02 19:08:40 +01:00
|
|
|
cursor_set_line(new_line);
|
|
|
|
cursor_set_column(new_column);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TextEdit::get_char_count() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int totalsize = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < text.size(); i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i > 0)
|
2015-01-02 19:08:40 +01:00
|
|
|
totalsize++; // incliude \n
|
2017-03-05 16:44:50 +01:00
|
|
|
totalsize += text[i].length();
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return totalsize; // omit last \n
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-06-12 18:31:22 +02:00
|
|
|
Size2 TextEdit::get_minimum_size() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return cache.style_normal->get_minimum_size();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
int TextEdit::get_visible_rows() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int total = cache.size.height;
|
|
|
|
total -= cache.style_normal->get_minimum_size().height;
|
|
|
|
total /= get_row_height();
|
2015-01-02 19:08:40 +01:00
|
|
|
return total;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
void TextEdit::adjust_viewport_to_cursor() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.line_ofs > cursor.line)
|
|
|
|
cursor.line_ofs = cursor.line;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int visible_width = cache.size.width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width;
|
2017-01-13 14:45:50 +01:00
|
|
|
if (v_scroll->is_visible_in_tree())
|
2017-03-05 16:44:50 +01:00
|
|
|
visible_width -= v_scroll->get_combined_minimum_size().width;
|
|
|
|
visible_width -= 20; // give it a little more space
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
//printf("rowofs %i, visrows %i, cursor.line %i\n",cursor.line_ofs,get_visible_rows(),cursor.line);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
int visible_rows = get_visible_rows();
|
2017-01-13 14:45:50 +01:00
|
|
|
if (h_scroll->is_visible_in_tree())
|
2017-03-05 16:44:50 +01:00
|
|
|
visible_rows -= ((h_scroll->get_combined_minimum_size().height - 1) / get_row_height());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.line >= (cursor.line_ofs + visible_rows))
|
|
|
|
cursor.line_ofs = cursor.line - visible_rows + 1;
|
|
|
|
if (cursor.line < cursor.line_ofs)
|
|
|
|
cursor.line_ofs = cursor.line;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int cursor_x = get_column_x_offset(cursor.column, text[cursor.line]);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor_x > (cursor.x_ofs + visible_width))
|
|
|
|
cursor.x_ofs = cursor_x - visible_width + 1;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (cursor_x < cursor.x_ofs)
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor.x_ofs = cursor_x;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
|
|
|
/*
|
2014-11-12 15:39:21 +01:00
|
|
|
get_range()->set_max(text.size());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-11-12 15:39:21 +01:00
|
|
|
get_range()->set_page(get_visible_rows());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-11-12 15:39:21 +01:00
|
|
|
get_range()->set((int)cursor.line_ofs);
|
2014-02-10 02:10:30 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2016-07-21 03:40:08 +02:00
|
|
|
void TextEdit::center_viewport_to_cursor() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.line_ofs > cursor.line)
|
|
|
|
cursor.line_ofs = cursor.line;
|
2016-07-21 03:40:08 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int visible_width = cache.size.width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width;
|
2017-01-13 14:45:50 +01:00
|
|
|
if (v_scroll->is_visible_in_tree())
|
2017-03-05 16:44:50 +01:00
|
|
|
visible_width -= v_scroll->get_combined_minimum_size().width;
|
|
|
|
visible_width -= 20; // give it a little more space
|
2016-07-21 03:40:08 +02:00
|
|
|
|
|
|
|
int visible_rows = get_visible_rows();
|
2017-01-13 14:45:50 +01:00
|
|
|
if (h_scroll->is_visible_in_tree())
|
2017-03-05 16:44:50 +01:00
|
|
|
visible_rows -= ((h_scroll->get_combined_minimum_size().height - 1) / get_row_height());
|
2016-07-21 03:40:08 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int max_ofs = text.size() - (scroll_past_end_of_file_enabled ? 1 : visible_rows);
|
|
|
|
cursor.line_ofs = CLAMP(cursor.line - (visible_rows / 2), 0, max_ofs);
|
2016-07-21 03:40:08 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int cursor_x = get_column_x_offset(cursor.column, text[cursor.line]);
|
2016-07-21 03:40:08 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor_x > (cursor.x_ofs + visible_width))
|
|
|
|
cursor.x_ofs = cursor_x - visible_width + 1;
|
2016-07-21 03:40:08 +02:00
|
|
|
|
|
|
|
if (cursor_x < cursor.x_ofs)
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor.x_ofs = cursor_x;
|
2016-07-21 03:40:08 +02:00
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2015-08-13 00:34:07 +02:00
|
|
|
void TextEdit::cursor_set_column(int p_col, bool p_adjust_viewport) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_col < 0)
|
|
|
|
p_col = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor.column = p_col;
|
|
|
|
if (cursor.column > get_line(cursor.line).length())
|
|
|
|
cursor.column = get_line(cursor.line).length();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor.last_fit_x = get_column_x_offset(cursor.column, get_line(cursor.line));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-08-13 00:34:07 +02:00
|
|
|
if (p_adjust_viewport)
|
|
|
|
adjust_viewport_to_cursor();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!cursor_changed_dirty) {
|
|
|
|
if (is_inside_tree())
|
2017-03-05 16:44:50 +01:00
|
|
|
MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
|
|
|
|
cursor_changed_dirty = true;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-08-13 00:34:07 +02:00
|
|
|
void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (setting_row)
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
setting_row = true;
|
|
|
|
if (p_row < 0)
|
|
|
|
p_row = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_row >= (int)text.size())
|
|
|
|
p_row = (int)text.size() - 1;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor.line = p_row;
|
|
|
|
cursor.column = get_char_pos_for(cursor.last_fit_x, get_line(cursor.line));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-08-13 00:34:07 +02:00
|
|
|
if (p_adjust_viewport)
|
|
|
|
adjust_viewport_to_cursor();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
setting_row = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!cursor_changed_dirty) {
|
|
|
|
if (is_inside_tree())
|
2017-03-05 16:44:50 +01:00
|
|
|
MessageQueue::get_singleton()->push_call(this, "_cursor_changed_emit");
|
|
|
|
cursor_changed_dirty = true;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TextEdit::cursor_get_column() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return cursor.column;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TextEdit::cursor_get_line() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return cursor.line;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-05-09 20:21:55 +02:00
|
|
|
bool TextEdit::cursor_get_blink_enabled() const {
|
|
|
|
return caret_blink_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::cursor_set_blink_enabled(const bool p_enabled) {
|
|
|
|
caret_blink_enabled = p_enabled;
|
|
|
|
|
|
|
|
if (p_enabled) {
|
|
|
|
caret_blink_timer->start();
|
|
|
|
} else {
|
|
|
|
caret_blink_timer->stop();
|
|
|
|
}
|
|
|
|
draw_caret = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
float TextEdit::cursor_get_blink_speed() const {
|
|
|
|
return caret_blink_timer->get_wait_time();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::cursor_set_blink_speed(const float p_speed) {
|
|
|
|
ERR_FAIL_COND(p_speed <= 0);
|
|
|
|
caret_blink_timer->set_wait_time(p_speed);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::cursor_set_block_mode(const bool p_enable) {
|
2016-07-12 17:07:17 +02:00
|
|
|
block_caret = p_enable;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TextEdit::cursor_is_block_mode() const {
|
|
|
|
return block_caret;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TextEdit::_scroll_moved(double p_to_val) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (updating_scrolls)
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-13 14:45:50 +01:00
|
|
|
if (h_scroll->is_visible_in_tree())
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor.x_ofs = h_scroll->get_value();
|
2017-01-13 14:45:50 +01:00
|
|
|
if (v_scroll->is_visible_in_tree())
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor.line_ofs = v_scroll->get_value();
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TextEdit::get_row_height() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return cache.font->get_height() + cache.line_spacing;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int TextEdit::get_char_pos_for(int p_px, String p_str) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int px = 0;
|
|
|
|
int c = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-04-17 15:24:30 +02:00
|
|
|
int tab_w = cache.font->get_char_size(' ').width * indent_size;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (c < p_str.length()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int w = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_str[c] == '\t') {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int left = px % tab_w;
|
|
|
|
if (left == 0)
|
|
|
|
w = tab_w;
|
2015-01-02 19:08:40 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
w = tab_w - px % tab_w; // is right...
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
w = cache.font->get_char_size(p_str[c], p_str[c + 1]).width;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_px < (px + w / 2))
|
2015-01-02 19:08:40 +01:00
|
|
|
break;
|
2017-03-05 16:44:50 +01:00
|
|
|
px += w;
|
2015-01-02 19:08:40 +01:00
|
|
|
c++;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return c;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int TextEdit::get_column_x_offset(int p_char, String p_str) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int px = 0;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-04-17 15:24:30 +02:00
|
|
|
int tab_w = cache.font->get_char_size(' ').width * indent_size;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_char; i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i >= p_str.length())
|
2015-01-02 19:08:40 +01:00
|
|
|
break;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_str[i] == '\t') {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int left = px % tab_w;
|
|
|
|
if (left == 0)
|
|
|
|
px += tab_w;
|
2015-01-02 19:08:40 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
px += tab_w - px % tab_w; // is right...
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
px += cache.font->get_char_size(p_str[i], p_str[i + 1]).width;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return px;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::insert_text_at_cursor(const String &p_text) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (selection.active) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
cursor_set_line(selection.from_line);
|
|
|
|
cursor_set_column(selection.from_column);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
|
|
|
|
selection.active = false;
|
|
|
|
selection.selecting_mode = Selection::MODE_NONE;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
_insert_text_at_cursor(p_text);
|
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const {
|
2017-04-06 17:35:08 +02:00
|
|
|
if (highlighted_word != String())
|
2016-09-12 15:52:29 +02:00
|
|
|
return CURSOR_POINTING_HAND;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int gutter = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width;
|
|
|
|
if ((completion_active && completion_rect.has_point(p_pos)) || p_pos.x < gutter) {
|
2015-01-02 19:08:40 +01:00
|
|
|
return CURSOR_ARROW;
|
|
|
|
}
|
|
|
|
return CURSOR_IBEAM;
|
2014-04-17 13:30:40 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::set_text(String p_text) {
|
2014-04-17 13:30:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
setting_text = true;
|
2015-04-21 01:51:52 +02:00
|
|
|
clear();
|
2015-01-02 19:08:40 +01:00
|
|
|
_insert_text_at_cursor(p_text);
|
2015-04-18 21:57:01 +02:00
|
|
|
clear_undo_history();
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor.column = 0;
|
|
|
|
cursor.line = 0;
|
|
|
|
cursor.x_ofs = 0;
|
|
|
|
cursor.line_ofs = 0;
|
|
|
|
cursor.last_fit_x = 0;
|
2015-01-02 19:08:40 +01:00
|
|
|
cursor_set_line(0);
|
|
|
|
cursor_set_column(0);
|
|
|
|
update();
|
2017-03-05 16:44:50 +01:00
|
|
|
setting_text = false;
|
2016-11-13 20:21:29 +01:00
|
|
|
_text_changed_emit();
|
2015-01-02 19:08:40 +01:00
|
|
|
//get_range()->set(0);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
String TextEdit::get_text() {
|
2015-01-02 19:08:40 +01:00
|
|
|
String longthing;
|
|
|
|
int len = text.size();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
longthing += text[i];
|
|
|
|
if (i != len - 1)
|
|
|
|
longthing += "\n";
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return longthing;
|
|
|
|
};
|
2014-12-17 02:31:57 +01:00
|
|
|
|
2016-09-12 15:52:29 +02:00
|
|
|
String TextEdit::get_text_for_lookup_completion() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int row, col;
|
|
|
|
_get_mouse_pos(get_local_mouse_pos(), row, col);
|
2016-09-12 15:52:29 +02:00
|
|
|
|
|
|
|
String longthing;
|
|
|
|
int len = text.size();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == row) {
|
|
|
|
longthing += text[i].substr(0, col);
|
|
|
|
longthing += String::chr(0xFFFF); //not unicode, represents the cursor
|
|
|
|
longthing += text[i].substr(col, text[i].size());
|
2016-09-12 15:52:29 +02:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
longthing += text[i];
|
2016-09-12 15:52:29 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i != len - 1)
|
|
|
|
longthing += "\n";
|
2016-09-12 15:52:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return longthing;
|
|
|
|
}
|
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
String TextEdit::get_text_for_completion() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
String longthing;
|
|
|
|
int len = text.size();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == cursor.line) {
|
|
|
|
longthing += text[i].substr(0, cursor.column);
|
|
|
|
longthing += String::chr(0xFFFF); //not unicode, represents the cursor
|
|
|
|
longthing += text[i].substr(cursor.column, text[i].size());
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
longthing += text[i];
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i != len - 1)
|
|
|
|
longthing += "\n";
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return longthing;
|
2014-12-17 02:31:57 +01:00
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
String TextEdit::get_line(int line) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (line < 0 || line >= text.size())
|
2015-01-02 19:08:40 +01:00
|
|
|
return "";
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return text[line];
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void TextEdit::_clear() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
clear_undo_history();
|
|
|
|
text.clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor.column = 0;
|
|
|
|
cursor.line = 0;
|
|
|
|
cursor.x_ofs = 0;
|
|
|
|
cursor.line_ofs = 0;
|
|
|
|
cursor.last_fit_x = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::clear() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
setting_text = true;
|
2015-01-02 19:08:40 +01:00
|
|
|
_clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
setting_text = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void TextEdit::set_readonly(bool p_readonly) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
readonly = p_readonly;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::set_wrap(bool p_wrap) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
wrap = p_wrap;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::set_max_chars(int p_max_chars) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
max_chars = p_max_chars;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-05-09 20:21:55 +02:00
|
|
|
void TextEdit::_reset_caret_blink_timer() {
|
|
|
|
if (caret_blink_enabled) {
|
|
|
|
caret_blink_timer->stop();
|
|
|
|
caret_blink_timer->start();
|
|
|
|
draw_caret = true;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::_toggle_draw_caret() {
|
|
|
|
draw_caret = !draw_caret;
|
2017-01-13 14:45:50 +01:00
|
|
|
if (is_visible_in_tree() && has_focus() && window_has_focus) {
|
2016-06-08 15:02:39 +02:00
|
|
|
update();
|
|
|
|
}
|
2016-05-09 20:21:55 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TextEdit::_update_caches() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cache.style_normal = get_stylebox("normal");
|
|
|
|
cache.style_focus = get_stylebox("focus");
|
|
|
|
cache.completion_background_color = get_color("completion_background_color");
|
|
|
|
cache.completion_selected_color = get_color("completion_selected_color");
|
|
|
|
cache.completion_existing_color = get_color("completion_existing_color");
|
|
|
|
cache.completion_font_color = get_color("completion_font_color");
|
|
|
|
cache.font = get_font("font");
|
|
|
|
cache.caret_color = get_color("caret_color");
|
|
|
|
cache.caret_background_color = get_color("caret_background_color");
|
|
|
|
cache.line_number_color = get_color("line_number_color");
|
|
|
|
cache.font_color = get_color("font_color");
|
|
|
|
cache.font_selected_color = get_color("font_selected_color");
|
|
|
|
cache.keyword_color = get_color("keyword_color");
|
|
|
|
cache.function_color = get_color("function_color");
|
|
|
|
cache.member_variable_color = get_color("member_variable_color");
|
|
|
|
cache.number_color = get_color("number_color");
|
|
|
|
cache.selection_color = get_color("selection_color");
|
|
|
|
cache.mark_color = get_color("mark_color");
|
|
|
|
cache.current_line_color = get_color("current_line_color");
|
|
|
|
cache.line_length_guideline_color = get_color("line_length_guideline_color");
|
|
|
|
cache.breakpoint_color = get_color("breakpoint_color");
|
|
|
|
cache.brace_mismatch_color = get_color("brace_mismatch_color");
|
|
|
|
cache.word_highlighted_color = get_color("word_highlighted_color");
|
|
|
|
cache.search_result_color = get_color("search_result_color");
|
|
|
|
cache.search_result_border_color = get_color("search_result_border_color");
|
|
|
|
cache.symbol_color = get_color("symbol_color");
|
|
|
|
cache.background_color = get_color("background_color");
|
|
|
|
cache.line_spacing = get_constant("line_spacing");
|
2015-01-02 19:08:40 +01:00
|
|
|
cache.row_height = cache.font->get_height() + cache.line_spacing;
|
2017-03-05 16:44:50 +01:00
|
|
|
cache.tab_icon = get_icon("tab");
|
2015-01-02 19:08:40 +01:00
|
|
|
text.set_font(cache.font);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::clear_colors() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
keywords.clear();
|
2016-11-06 14:50:23 +01:00
|
|
|
color_regions.clear();
|
2015-01-02 19:08:40 +01:00
|
|
|
text.clear_caches();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::add_keyword_color(const String &p_keyword, const Color &p_color) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
keywords[p_keyword] = p_color;
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::add_color_region(const String &p_begin_key, const String &p_end_key, const Color &p_color, bool p_line_only) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
color_regions.push_back(ColorRegion(p_begin_key, p_end_key, p_color, p_line_only));
|
2015-01-02 19:08:40 +01:00
|
|
|
text.clear_caches();
|
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::set_syntax_coloring(bool p_enabled) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
syntax_coloring = p_enabled;
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TextEdit::is_syntax_coloring_enabled() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return syntax_coloring;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2015-11-29 17:02:35 +01:00
|
|
|
void TextEdit::set_auto_indent(bool p_auto_indent) {
|
|
|
|
auto_indent = p_auto_indent;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TextEdit::cut() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-15 13:02:38 +01:00
|
|
|
if (!selection.active) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-15 13:02:38 +01:00
|
|
|
String clipboard = text[cursor.line];
|
|
|
|
OS::get_singleton()->set_clipboard(clipboard);
|
|
|
|
cursor_set_line(cursor.line);
|
|
|
|
cursor_set_column(0);
|
2017-03-05 16:44:50 +01:00
|
|
|
_remove_text(cursor.line, 0, cursor.line, text[cursor.line].length());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-15 13:02:38 +01:00
|
|
|
backspace_at_cursor();
|
|
|
|
update();
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor_set_line(cursor.line + 1);
|
2016-03-15 13:02:38 +01:00
|
|
|
cut_copy_line = true;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-15 13:02:38 +01:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String clipboard = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
|
2016-03-15 13:02:38 +01:00
|
|
|
OS::get_singleton()->set_clipboard(clipboard);
|
|
|
|
|
|
|
|
cursor_set_line(selection.from_line);
|
|
|
|
cursor_set_column(selection.from_column);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
|
|
|
|
selection.active = false;
|
|
|
|
selection.selecting_mode = Selection::MODE_NONE;
|
2016-03-15 13:02:38 +01:00
|
|
|
update();
|
|
|
|
cut_copy_line = false;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::copy() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!selection.active)
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-15 13:02:38 +01:00
|
|
|
if (!selection.active) {
|
2017-03-05 16:44:50 +01:00
|
|
|
String clipboard = _base_get_text(cursor.line, 0, cursor.line, text[cursor.line].length());
|
2016-03-15 13:02:38 +01:00
|
|
|
OS::get_singleton()->set_clipboard(clipboard);
|
|
|
|
cut_copy_line = true;
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
String clipboard = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
|
2016-03-15 13:02:38 +01:00
|
|
|
OS::get_singleton()->set_clipboard(clipboard);
|
|
|
|
cut_copy_line = false;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-03-15 13:02:38 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TextEdit::paste() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-15 13:02:38 +01:00
|
|
|
String clipboard = OS::get_singleton()->get_clipboard();
|
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (selection.active) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selection.active = false;
|
|
|
|
selection.selecting_mode = Selection::MODE_NONE;
|
|
|
|
_remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
|
2015-01-02 19:08:40 +01:00
|
|
|
cursor_set_line(selection.from_line);
|
|
|
|
cursor_set_column(selection.from_column);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-15 13:02:38 +01:00
|
|
|
} else if (cut_copy_line) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-15 13:02:38 +01:00
|
|
|
cursor_set_column(0);
|
2017-03-05 16:44:50 +01:00
|
|
|
String ins = "\n";
|
2016-03-15 13:02:38 +01:00
|
|
|
clipboard += ins;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
_insert_text_at_cursor(clipboard);
|
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::select_all() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (text.size() == 1 && text[0].length() == 0)
|
2015-01-02 19:08:40 +01:00
|
|
|
return;
|
2017-03-05 16:44:50 +01:00
|
|
|
selection.active = true;
|
|
|
|
selection.from_line = 0;
|
|
|
|
selection.from_column = 0;
|
|
|
|
selection.selecting_line = 0;
|
|
|
|
selection.selecting_column = 0;
|
|
|
|
selection.to_line = text.size() - 1;
|
|
|
|
selection.to_column = text[selection.to_line].length();
|
|
|
|
selection.selecting_mode = Selection::MODE_SHIFT;
|
|
|
|
selection.shiftclick_left = true;
|
|
|
|
cursor_set_line(selection.to_line, false);
|
|
|
|
cursor_set_column(selection.to_column, false);
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::deselect() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selection.active = false;
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::select(int p_from_line, int p_from_column, int p_to_line, int p_to_column) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_from_line >= text.size())
|
|
|
|
p_from_line = text.size() - 1;
|
|
|
|
if (p_from_column >= text[p_from_line].length())
|
|
|
|
p_from_column = text[p_from_line].length();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_to_line >= text.size())
|
|
|
|
p_to_line = text.size() - 1;
|
|
|
|
if (p_to_column >= text[p_to_line].length())
|
|
|
|
p_to_column = text[p_to_line].length();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selection.from_line = p_from_line;
|
|
|
|
selection.from_column = p_from_column;
|
|
|
|
selection.to_line = p_to_line;
|
|
|
|
selection.to_column = p_to_column;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selection.active = true;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (selection.from_line == selection.to_line) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (selection.from_column == selection.to_column) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selection.active = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (selection.from_column > selection.to_column) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-08-13 00:34:07 +02:00
|
|
|
selection.shiftclick_left = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
SWAP(selection.from_column, selection.to_column);
|
2015-08-13 00:34:07 +02:00
|
|
|
} else {
|
|
|
|
|
|
|
|
selection.shiftclick_left = true;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (selection.from_line > selection.to_line) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-08-13 00:34:07 +02:00
|
|
|
selection.shiftclick_left = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
SWAP(selection.from_line, selection.to_line);
|
|
|
|
SWAP(selection.from_column, selection.to_column);
|
2015-08-13 00:34:07 +02:00
|
|
|
} else {
|
|
|
|
|
|
|
|
selection.shiftclick_left = true;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TextEdit::is_selection_active() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return selection.active;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
int TextEdit::get_selection_from_line() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!selection.active, -1);
|
2015-01-02 19:08:40 +01:00
|
|
|
return selection.from_line;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
int TextEdit::get_selection_from_column() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!selection.active, -1);
|
2015-01-02 19:08:40 +01:00
|
|
|
return selection.from_column;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
int TextEdit::get_selection_to_line() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!selection.active, -1);
|
2015-01-02 19:08:40 +01:00
|
|
|
return selection.to_line;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
int TextEdit::get_selection_to_column() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!selection.active, -1);
|
2015-01-02 19:08:40 +01:00
|
|
|
return selection.to_column;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String TextEdit::get_selection_text() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!selection.active)
|
|
|
|
return "";
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2014-05-06 11:36:39 +02:00
|
|
|
String TextEdit::get_word_under_cursor() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
int prev_cc = cursor.column;
|
2017-03-05 16:44:50 +01:00
|
|
|
while (prev_cc > 0) {
|
|
|
|
bool is_char = _is_text_char(text[cursor.line][prev_cc - 1]);
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!is_char)
|
|
|
|
break;
|
|
|
|
--prev_cc;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
int next_cc = cursor.column;
|
2017-03-05 16:44:50 +01:00
|
|
|
while (next_cc < text[cursor.line].length()) {
|
2015-01-02 19:08:40 +01:00
|
|
|
bool is_char = _is_text_char(text[cursor.line][next_cc]);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!is_char)
|
2015-01-02 19:08:40 +01:00
|
|
|
break;
|
2017-03-05 16:44:50 +01:00
|
|
|
++next_cc;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
|
|
|
if (prev_cc == cursor.column || next_cc == cursor.column)
|
|
|
|
return "";
|
2017-03-05 16:44:50 +01:00
|
|
|
return text[cursor.line].substr(prev_cc, next_cc - prev_cc);
|
2014-05-06 11:36:39 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-28 18:25:45 +02:00
|
|
|
void TextEdit::set_search_text(const String &p_search_text) {
|
|
|
|
search_text = p_search_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::set_search_flags(uint32_t p_flags) {
|
|
|
|
search_flags = p_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::set_current_search_result(int line, int col) {
|
|
|
|
search_result_line = line;
|
|
|
|
search_result_col = col;
|
2016-05-30 18:15:41 +02:00
|
|
|
update();
|
2016-05-28 18:25:45 +02:00
|
|
|
}
|
|
|
|
|
2016-03-16 22:20:42 +01:00
|
|
|
void TextEdit::set_highlight_all_occurrences(const bool p_enabled) {
|
|
|
|
highlight_all_occurrences = p_enabled;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-07-11 16:20:01 +02:00
|
|
|
bool TextEdit::is_highlight_all_occurrences_enabled() const {
|
|
|
|
return highlight_all_occurrences;
|
|
|
|
}
|
|
|
|
|
2016-05-28 18:25:45 +02:00
|
|
|
int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column) {
|
2016-03-16 22:20:42 +01:00
|
|
|
int col = -1;
|
|
|
|
|
|
|
|
if (p_key.length() > 0 && p_search.length() > 0) {
|
|
|
|
if (p_from_column < 0 || p_from_column > p_search.length()) {
|
|
|
|
p_from_column = 0;
|
|
|
|
}
|
|
|
|
|
2016-05-28 18:25:45 +02:00
|
|
|
while (col == -1 && p_from_column <= p_search.length()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_search_flags & SEARCH_MATCH_CASE) {
|
|
|
|
col = p_search.find(p_key, p_from_column);
|
2016-05-28 18:25:45 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
col = p_search.findn(p_key, p_from_column);
|
2016-05-28 18:25:45 +02:00
|
|
|
}
|
2016-03-17 21:35:04 +01:00
|
|
|
|
|
|
|
// whole words only
|
2017-03-05 16:44:50 +01:00
|
|
|
if (col != -1 && p_search_flags & SEARCH_WHOLE_WORDS) {
|
|
|
|
p_from_column = col;
|
2016-03-17 21:35:04 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (col > 0 && _is_text_char(p_search[col - 1])) {
|
2016-03-17 21:35:04 +01:00
|
|
|
col = -1;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if ((col + p_key.length()) < p_search.length() && _is_text_char(p_search[col + p_key.length()])) {
|
2016-03-17 21:35:04 +01:00
|
|
|
col = -1;
|
|
|
|
}
|
2016-03-16 22:20:42 +01:00
|
|
|
}
|
2016-03-17 21:35:04 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
p_from_column += 1;
|
2016-03-16 22:20:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PoolVector<int> TextEdit::_search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int col, line;
|
|
|
|
if (search(p_key, p_search_flags, p_from_line, p_from_column, col, line)) {
|
2017-01-07 22:25:37 +01:00
|
|
|
PoolVector<int> result;
|
2015-01-02 19:08:40 +01:00
|
|
|
result.resize(2);
|
2017-03-05 16:44:50 +01:00
|
|
|
result.set(0, line);
|
|
|
|
result.set(1, col);
|
2015-01-02 19:08:40 +01:00
|
|
|
return result;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-07 22:25:37 +01:00
|
|
|
return PoolVector<int>();
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column, int &r_line, int &r_column) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_key.length() == 0)
|
2015-01-02 19:08:40 +01:00
|
|
|
return false;
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_from_line, text.size(), false);
|
|
|
|
ERR_FAIL_INDEX_V(p_from_column, text[p_from_line].length() + 1, false);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
//search through the whole documment, but start by current line
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int line = -1;
|
|
|
|
int pos = -1;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
line = p_from_line;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < text.size() + 1; i++) {
|
2015-01-02 19:08:40 +01:00
|
|
|
//backwards is broken...
|
|
|
|
//int idx=(p_search_flags&SEARCH_BACKWARDS)?(text.size()-i):i; //do backwards seearch
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (line < 0) {
|
|
|
|
line = text.size() - 1;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (line == text.size()) {
|
|
|
|
line = 0;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
String text_line = text[line];
|
2017-03-05 16:44:50 +01:00
|
|
|
int from_column = 0;
|
|
|
|
if (line == p_from_line) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == text.size()) {
|
2015-01-02 19:08:40 +01:00
|
|
|
//wrapped
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_search_flags & SEARCH_BACKWARDS) {
|
|
|
|
from_column = text_line.length();
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
from_column = 0;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
from_column = p_from_column;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_search_flags & SEARCH_BACKWARDS)
|
|
|
|
from_column = text_line.length() - 1;
|
2015-01-02 19:08:40 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
from_column = 0;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pos = -1;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int pos_from = 0;
|
|
|
|
int last_pos = -1;
|
|
|
|
while ((last_pos = (p_search_flags & SEARCH_MATCH_CASE) ? text_line.find(p_key, pos_from) : text_line.findn(p_key, pos_from)) != -1) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_search_flags & SEARCH_BACKWARDS) {
|
2016-05-28 18:23:49 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (last_pos > from_column)
|
2016-05-28 18:23:49 +02:00
|
|
|
break;
|
2017-03-05 16:44:50 +01:00
|
|
|
pos = last_pos;
|
2016-05-28 18:23:49 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (last_pos >= from_column) {
|
|
|
|
pos = last_pos;
|
2016-05-28 18:23:49 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pos_from = last_pos + p_key.length();
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (pos != -1 && (p_search_flags & SEARCH_WHOLE_WORDS)) {
|
2015-01-02 19:08:40 +01:00
|
|
|
//validate for whole words
|
2017-03-05 16:44:50 +01:00
|
|
|
if (pos > 0 && _is_text_char(text_line[pos - 1]))
|
|
|
|
pos = -1;
|
|
|
|
else if (_is_text_char(text_line[pos + p_key.length()]))
|
|
|
|
pos = -1;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (pos != -1)
|
2015-01-02 19:08:40 +01:00
|
|
|
break;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_search_flags & SEARCH_BACKWARDS)
|
2015-01-02 19:08:40 +01:00
|
|
|
line--;
|
|
|
|
else
|
|
|
|
line++;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (pos == -1) {
|
|
|
|
r_line = -1;
|
|
|
|
r_column = -1;
|
2015-01-02 19:08:40 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_line = line;
|
|
|
|
r_column = pos;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::_cursor_changed_emit() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
emit_signal("cursor_changed");
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor_changed_dirty = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::_text_changed_emit() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
emit_signal("text_changed");
|
2017-03-05 16:44:50 +01:00
|
|
|
text_changed_dirty = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::set_line_as_marked(int p_line, bool p_marked) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(p_line, text.size());
|
|
|
|
text.set_marked(p_line, p_marked);
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TextEdit::is_line_set_as_breakpoint(int p_line) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_line, text.size(), false);
|
2015-01-02 19:08:40 +01:00
|
|
|
return text.is_breakpoint(p_line);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::set_line_as_breakpoint(int p_line, bool p_breakpoint) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(p_line, text.size());
|
|
|
|
text.set_breakpoint(p_line, p_breakpoint);
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::get_breakpoints(List<int> *p_breakpoints) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < text.size(); i++) {
|
2015-01-02 19:08:40 +01:00
|
|
|
if (text.is_breakpoint(i))
|
|
|
|
p_breakpoints->push_back(i);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TextEdit::get_line_count() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return text.size();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::_do_text_op(const TextOperation &p_op, bool p_reverse) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(p_op.type == TextOperation::TYPE_NONE);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool insert = p_op.type == TextOperation::TYPE_INSERT;
|
2015-01-02 19:08:40 +01:00
|
|
|
if (p_reverse)
|
2017-03-05 16:44:50 +01:00
|
|
|
insert = !insert;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (insert) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
int check_line;
|
|
|
|
int check_column;
|
2017-03-05 16:44:50 +01:00
|
|
|
_base_insert_text(p_op.from_line, p_op.from_column, p_op.text, check_line, check_column);
|
|
|
|
ERR_FAIL_COND(check_line != p_op.to_line); // BUG
|
|
|
|
ERR_FAIL_COND(check_column != p_op.to_column); // BUG
|
2015-01-02 19:08:40 +01:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_base_remove_text(p_op.from_line, p_op.from_column, p_op.to_line, p_op.to_column);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::_clear_redo() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (undo_stack_pos == NULL)
|
2015-01-02 19:08:40 +01:00
|
|
|
return; //nothing to clear
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
_push_current_op();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (undo_stack_pos) {
|
2015-01-02 19:08:40 +01:00
|
|
|
List<TextOperation>::Element *elem = undo_stack_pos;
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_stack_pos = undo_stack_pos->next();
|
2015-01-02 19:08:40 +01:00
|
|
|
undo_stack.erase(elem);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::undo() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
_push_current_op();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (undo_stack_pos == NULL) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!undo_stack.size())
|
|
|
|
return; //nothing to undo
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_stack_pos = undo_stack.back();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (undo_stack_pos == undo_stack.front())
|
2015-01-02 19:08:40 +01:00
|
|
|
return; // at the bottom of the undo stack
|
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_stack_pos = undo_stack_pos->prev();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-13 21:08:12 +01:00
|
|
|
TextOperation op = undo_stack_pos->get();
|
|
|
|
_do_text_op(op, true);
|
2017-03-05 16:44:50 +01:00
|
|
|
current_op.version = op.prev_version;
|
|
|
|
if (undo_stack_pos->get().chain_backward) {
|
|
|
|
while (true) {
|
2016-06-14 13:48:34 +02:00
|
|
|
ERR_BREAK(!undo_stack_pos->prev());
|
2015-01-02 19:08:40 +01:00
|
|
|
undo_stack_pos = undo_stack_pos->prev();
|
2016-03-13 21:08:12 +01:00
|
|
|
op = undo_stack_pos->get();
|
|
|
|
_do_text_op(op, true);
|
|
|
|
current_op.version = op.prev_version;
|
2016-06-14 13:48:34 +02:00
|
|
|
if (undo_stack_pos->get().chain_forward) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-13 21:40:28 +02:00
|
|
|
if (undo_stack_pos->get().type == TextOperation::TYPE_REMOVE) {
|
|
|
|
cursor_set_line(undo_stack_pos->get().to_line);
|
|
|
|
cursor_set_column(undo_stack_pos->get().to_column);
|
2016-06-13 21:55:26 +02:00
|
|
|
_cancel_code_hint();
|
2016-06-13 21:40:28 +02:00
|
|
|
} else {
|
|
|
|
cursor_set_line(undo_stack_pos->get().from_line);
|
|
|
|
cursor_set_column(undo_stack_pos->get().from_column);
|
|
|
|
}
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::redo() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
_push_current_op();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (undo_stack_pos == NULL)
|
2015-01-02 19:08:40 +01:00
|
|
|
return; //nothing to do.
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-03-13 21:08:12 +01:00
|
|
|
TextOperation op = undo_stack_pos->get();
|
|
|
|
_do_text_op(op, false);
|
|
|
|
current_op.version = op.version;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (undo_stack_pos->get().chain_forward) {
|
2016-06-14 13:48:34 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
2016-06-14 13:48:34 +02:00
|
|
|
ERR_BREAK(!undo_stack_pos->next());
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_stack_pos = undo_stack_pos->next();
|
2016-03-13 21:08:12 +01:00
|
|
|
op = undo_stack_pos->get();
|
|
|
|
_do_text_op(op, false);
|
|
|
|
current_op.version = op.version;
|
2016-06-14 13:48:34 +02:00
|
|
|
if (undo_stack_pos->get().chain_backward)
|
|
|
|
break;
|
|
|
|
}
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-13 21:08:12 +01:00
|
|
|
cursor_set_line(undo_stack_pos->get().to_line);
|
|
|
|
cursor_set_column(undo_stack_pos->get().to_column);
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_stack_pos = undo_stack_pos->next();
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::clear_undo_history() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
saved_version = 0;
|
|
|
|
current_op.type = TextOperation::TYPE_NONE;
|
|
|
|
undo_stack_pos = NULL;
|
2015-01-02 19:08:40 +01:00
|
|
|
undo_stack.clear();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-04-06 08:36:29 +02:00
|
|
|
void TextEdit::begin_complex_operation() {
|
2015-01-02 19:08:40 +01:00
|
|
|
_push_current_op();
|
2017-03-05 16:44:50 +01:00
|
|
|
next_operation_is_complex = true;
|
2014-04-26 14:42:19 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-04-06 08:36:29 +02:00
|
|
|
void TextEdit::end_complex_operation() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
_push_current_op();
|
|
|
|
ERR_FAIL_COND(undo_stack.size() == 0);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (undo_stack.back()->get().chain_forward) {
|
|
|
|
undo_stack.back()->get().chain_forward = false;
|
2015-01-02 19:08:40 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
undo_stack.back()->get().chain_backward = true;
|
2014-04-26 14:42:19 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-04-26 14:42:19 +02:00
|
|
|
void TextEdit::_push_current_op() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (current_op.type == TextOperation::TYPE_NONE)
|
2015-01-02 19:08:40 +01:00
|
|
|
return; // do nothing
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (next_operation_is_complex) {
|
|
|
|
current_op.chain_forward = true;
|
|
|
|
next_operation_is_complex = false;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
undo_stack.push_back(current_op);
|
2017-03-05 16:44:50 +01:00
|
|
|
current_op.type = TextOperation::TYPE_NONE;
|
|
|
|
current_op.text = "";
|
|
|
|
current_op.chain_forward = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-04-17 15:24:30 +02:00
|
|
|
void TextEdit::set_indent_using_spaces(const bool p_use_spaces) {
|
|
|
|
indent_using_spaces = p_use_spaces;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TextEdit::is_indent_using_spaces() const {
|
|
|
|
return indent_using_spaces;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::set_indent_size(const int p_size) {
|
2016-03-11 19:10:01 +01:00
|
|
|
ERR_FAIL_COND(p_size <= 0);
|
2017-04-17 15:24:30 +02:00
|
|
|
indent_size = p_size;
|
|
|
|
text.set_indent_size(p_size);
|
|
|
|
|
|
|
|
space_indent = "";
|
|
|
|
for (int i = 0; i < p_size; i++) {
|
|
|
|
space_indent += " ";
|
|
|
|
}
|
|
|
|
|
2016-03-11 19:10:01 +01:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TextEdit::set_draw_tabs(bool p_draw) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
draw_tabs = p_draw;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool TextEdit::is_drawing_tabs() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return draw_tabs;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-03-31 21:49:30 +02:00
|
|
|
void TextEdit::set_insert_mode(bool p_enabled) {
|
|
|
|
insert_mode = p_enabled;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TextEdit::is_insert_mode() const {
|
|
|
|
return insert_mode;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
uint32_t TextEdit::get_version() const {
|
2015-01-02 19:08:40 +01:00
|
|
|
return current_op.version;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
uint32_t TextEdit::get_saved_version() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return saved_version;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
void TextEdit::tag_saved_version() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
saved_version = get_version();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TextEdit::get_v_scroll() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-04 05:16:14 +01:00
|
|
|
return v_scroll->get_value();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
void TextEdit::set_v_scroll(int p_scroll) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-04 05:16:14 +01:00
|
|
|
v_scroll->set_value(p_scroll);
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor.line_ofs = p_scroll;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TextEdit::get_h_scroll() const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-04 05:16:14 +01:00
|
|
|
return h_scroll->get_value();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
void TextEdit::set_h_scroll(int p_scroll) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-01-04 05:16:14 +01:00
|
|
|
h_scroll->set_value(p_scroll);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::set_completion(bool p_enabled, const Vector<String> &p_prefixes) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
completion_prefixes.clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_enabled = p_enabled;
|
|
|
|
for (int i = 0; i < p_prefixes.size(); i++)
|
2015-01-02 19:08:40 +01:00
|
|
|
completion_prefixes.insert(p_prefixes[i]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::_confirm_completion() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-13 21:55:26 +02:00
|
|
|
begin_complex_operation();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-13 21:55:26 +02:00
|
|
|
_remove_text(cursor.line, cursor.column - completion_base.length(), cursor.line, cursor.column);
|
|
|
|
cursor_set_column(cursor.column - completion_base.length(), false);
|
|
|
|
insert_text_at_cursor(completion_current);
|
|
|
|
|
|
|
|
if (completion_current.ends_with("(") && auto_brace_completion_enabled) {
|
|
|
|
insert_text_at_cursor(")");
|
|
|
|
cursor.column--;
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-13 21:55:26 +02:00
|
|
|
end_complex_operation();
|
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
_cancel_completion();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
void TextEdit::_cancel_code_hint() {
|
2016-10-05 10:19:08 +02:00
|
|
|
|
|
|
|
VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 0);
|
2016-10-10 13:21:37 +02:00
|
|
|
raised_from_completion = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_hint = "";
|
2014-12-17 02:31:57 +01:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TextEdit::_cancel_completion() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-10-05 10:19:08 +02:00
|
|
|
VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 0);
|
2016-10-10 13:21:37 +02:00
|
|
|
raised_from_completion = false;
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!completion_active)
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_active = false;
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
static bool _is_completable(CharType c) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return !_is_symbol(c) || c == '"' || c == '\'';
|
2014-12-17 02:31:57 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TextEdit::_update_completion_candidates() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
String l = text[cursor.line];
|
2017-03-05 16:44:50 +01:00
|
|
|
int cofs = CLAMP(cursor.column, 0, l.length());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
String s;
|
2015-01-03 17:03:13 +01:00
|
|
|
|
|
|
|
//look for keywords first
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool inquote = false;
|
|
|
|
int first_quote = -1;
|
2015-06-26 06:14:31 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int c = cofs - 1;
|
|
|
|
while (c >= 0) {
|
|
|
|
if (l[c] == '"' || l[c] == '\'') {
|
|
|
|
inquote = !inquote;
|
|
|
|
if (first_quote == -1)
|
|
|
|
first_quote = c;
|
2015-06-26 06:14:31 +02:00
|
|
|
}
|
|
|
|
c--;
|
|
|
|
}
|
2015-01-03 17:03:13 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool pre_keyword = false;
|
|
|
|
bool cancel = false;
|
2015-06-26 06:14:31 +02:00
|
|
|
|
|
|
|
//print_line("inquote: "+itos(inquote)+"first quote "+itos(first_quote)+" cofs-1 "+itos(cofs-1));
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!inquote && first_quote == cofs - 1) {
|
2015-06-26 06:14:31 +02:00
|
|
|
//no completion here
|
|
|
|
//print_line("cancel!");
|
2017-03-05 16:44:50 +01:00
|
|
|
cancel = true;
|
|
|
|
} else if (inquote && first_quote != -1) {
|
2015-06-26 06:14:31 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
s = l.substr(first_quote, cofs - first_quote);
|
2015-06-26 06:14:31 +02:00
|
|
|
//print_line("s: 1"+s);
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cofs > 0 && l[cofs - 1] == ' ') {
|
|
|
|
int kofs = cofs - 1;
|
2015-01-03 17:03:13 +01:00
|
|
|
String kw;
|
2017-03-05 16:44:50 +01:00
|
|
|
while (kofs >= 0 && l[kofs] == ' ')
|
2015-01-03 17:03:13 +01:00
|
|
|
kofs--;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (kofs >= 0 && l[kofs] > 32 && _is_completable(l[kofs])) {
|
|
|
|
kw = String::chr(l[kofs]) + kw;
|
2015-01-03 17:03:13 +01:00
|
|
|
kofs--;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pre_keyword = keywords.has(kw);
|
2015-06-26 06:14:31 +02:00
|
|
|
//print_line("KW "+kw+"? "+itos(pre_keyword));
|
2015-01-03 17:03:13 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (cofs > 0 && l[cofs - 1] > 32 && _is_completable(l[cofs - 1])) {
|
|
|
|
s = String::chr(l[cofs - 1]) + s;
|
|
|
|
if (l[cofs - 1] == '\'' || l[cofs - 1] == '"' || l[cofs - 1] == '$')
|
2015-01-03 17:03:13 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
cofs--;
|
|
|
|
}
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2015-01-03 17:03:13 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.column > 0 && l[cursor.column - 1] == '(' && !pre_keyword && !completion_strings[0].begins_with("\"")) {
|
2016-05-07 13:01:56 +02:00
|
|
|
cancel = true;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cancel || (!pre_keyword && s == "" && (cofs == 0 || !completion_prefixes.has(String::chr(l[cofs - 1]))))) {
|
2015-01-02 19:08:40 +01:00
|
|
|
//none to complete, cancel
|
|
|
|
_cancel_completion();
|
|
|
|
return;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
completion_options.clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_index = 0;
|
|
|
|
completion_base = s;
|
2016-06-13 21:55:26 +02:00
|
|
|
Vector<float> sim_cache;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < completion_strings.size(); i++) {
|
2016-07-03 16:34:23 +02:00
|
|
|
if (s == completion_strings[i]) {
|
|
|
|
// A perfect match, stop completion
|
|
|
|
_cancel_completion();
|
|
|
|
return;
|
|
|
|
}
|
2017-01-08 07:01:52 +01:00
|
|
|
|
2016-06-13 21:55:26 +02:00
|
|
|
if (s.is_subsequence_ofi(completion_strings[i])) {
|
2017-03-05 16:44:50 +01:00
|
|
|
// don't remove duplicates if no input is provided
|
2016-06-13 21:55:26 +02:00
|
|
|
if (s != "" && completion_options.find(completion_strings[i]) != -1) {
|
2016-05-03 20:48:35 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-06-13 21:55:26 +02:00
|
|
|
// Calculate the similarity to keep completions in good order
|
2016-07-03 16:32:30 +02:00
|
|
|
float similarity;
|
|
|
|
if (completion_strings[i].to_lower().begins_with(s.to_lower())) {
|
|
|
|
// Substrings are the best candidates
|
|
|
|
similarity = 1.1;
|
|
|
|
} else {
|
|
|
|
// Otherwise compute the similarity
|
|
|
|
similarity = s.to_lower().similarity(completion_strings[i].to_lower());
|
|
|
|
}
|
|
|
|
|
2016-06-13 21:55:26 +02:00
|
|
|
int comp_size = completion_options.size();
|
|
|
|
if (comp_size == 0) {
|
|
|
|
completion_options.push_back(completion_strings[i]);
|
|
|
|
sim_cache.push_back(similarity);
|
|
|
|
} else {
|
|
|
|
float comp_sim;
|
|
|
|
int pos = 0;
|
|
|
|
do {
|
|
|
|
comp_sim = sim_cache[pos++];
|
2017-03-05 16:44:50 +01:00
|
|
|
} while (pos < comp_size && similarity < comp_sim);
|
2016-07-03 16:32:30 +02:00
|
|
|
pos = similarity > comp_sim ? pos - 1 : pos; // Pos will be off by one
|
2016-06-13 21:55:26 +02:00
|
|
|
completion_options.insert(pos, completion_strings[i]);
|
|
|
|
sim_cache.insert(pos, similarity);
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (completion_options.size() == 0) {
|
2015-01-02 19:08:40 +01:00
|
|
|
//no options to complete, cancel
|
|
|
|
_cancel_completion();
|
2017-01-08 07:01:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-06-13 21:55:26 +02:00
|
|
|
// The top of the list is the best match
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_current = completion_options[0];
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#if 0 // even there's only one option, user still get the chance to choose using it or not
|
2015-01-02 19:08:40 +01:00
|
|
|
if (completion_options.size()==1) {
|
|
|
|
//one option to complete, just complete it automagically
|
|
|
|
_confirm_completion();
|
2017-01-14 12:26:56 +01:00
|
|
|
//insert_text_at_cursor(completion_options[0].substr(s.length(),completion_options[0].length()-s.length()));
|
2015-01-02 19:08:40 +01:00
|
|
|
_cancel_completion();
|
|
|
|
return;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
}
|
2014-11-12 15:39:21 +01:00
|
|
|
#endif
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_enabled = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::query_code_comple() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-12-17 02:31:57 +01:00
|
|
|
String l = text[cursor.line];
|
2017-03-05 16:44:50 +01:00
|
|
|
int ofs = CLAMP(cursor.column, 0, l.length());
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool inquote = false;
|
2015-06-26 06:14:31 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int c = ofs - 1;
|
|
|
|
while (c >= 0) {
|
|
|
|
if (l[c] == '"' || l[c] == '\'')
|
|
|
|
inquote = !inquote;
|
2015-06-26 06:14:31 +02:00
|
|
|
c--;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (ofs > 0 && (inquote || _is_completable(l[ofs - 1]) || completion_prefixes.has(String::chr(l[ofs - 1]))))
|
2014-12-17 02:31:57 +01:00
|
|
|
emit_signal("request_completion");
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::set_code_hint(const String &p_hint) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-10-05 10:19:08 +02:00
|
|
|
VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 1);
|
2016-10-10 13:21:37 +02:00
|
|
|
raised_from_completion = true;
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_hint = p_hint;
|
|
|
|
completion_hint_offset = -0xFFFF;
|
2014-12-17 02:31:57 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::code_complete(const Vector<String> &p_strings) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-10-05 10:19:08 +02:00
|
|
|
VisualServer::get_singleton()->canvas_item_set_z(get_canvas_item(), 1);
|
2016-10-10 13:21:37 +02:00
|
|
|
raised_from_completion = true;
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_strings = p_strings;
|
|
|
|
completion_active = true;
|
|
|
|
completion_current = "";
|
|
|
|
completion_index = 0;
|
2015-01-02 19:08:40 +01:00
|
|
|
_update_completion_candidates();
|
|
|
|
//
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String TextEdit::get_word_at_pos(const Vector2 &p_pos) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int row, col;
|
2016-09-12 15:52:29 +02:00
|
|
|
_get_mouse_pos(p_pos, row, col);
|
|
|
|
|
|
|
|
String s = text[row];
|
2017-03-05 16:44:50 +01:00
|
|
|
if (s.length() == 0)
|
2016-09-12 15:52:29 +02:00
|
|
|
return "";
|
2017-03-05 16:44:50 +01:00
|
|
|
int beg = CLAMP(col, 0, s.length());
|
|
|
|
int end = beg;
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (s[beg] > 32 || beg == s.length()) {
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (beg > 0 && s[beg - 1] > 32 && (symbol == _is_symbol(s[beg - 1]))) {
|
2016-09-12 15:52:29 +02:00
|
|
|
beg--;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
while (end < s.length() && s[end + 1] > 32 && (symbol == _is_symbol(s[end + 1]))) {
|
2016-09-12 15:52:29 +02:00
|
|
|
end++;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (end < s.length())
|
|
|
|
end += 1;
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return s.substr(beg, end - beg);
|
2016-09-12 15:52:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String TextEdit::get_tooltip(const Point2 &p_pos) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
if (!tooltip_obj)
|
|
|
|
return Control::get_tooltip(p_pos);
|
2017-03-05 16:44:50 +01:00
|
|
|
int row, col;
|
2015-11-07 13:39:03 +01:00
|
|
|
_get_mouse_pos(p_pos, row, col);
|
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
String s = text[row];
|
2017-03-05 16:44:50 +01:00
|
|
|
if (s.length() == 0)
|
2015-01-02 19:08:40 +01:00
|
|
|
return Control::get_tooltip(p_pos);
|
2017-03-05 16:44:50 +01:00
|
|
|
int beg = CLAMP(col, 0, s.length());
|
|
|
|
int end = beg;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (s[beg] > 32 || beg == s.length()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (beg > 0 && s[beg - 1] > 32 && (symbol == _is_symbol(s[beg - 1]))) {
|
2015-01-02 19:08:40 +01:00
|
|
|
beg--;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
while (end < s.length() && s[end + 1] > 32 && (symbol == _is_symbol(s[end + 1]))) {
|
2015-01-02 19:08:40 +01:00
|
|
|
end++;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (end < s.length())
|
|
|
|
end += 1;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String tt = tooltip_obj->call(tooltip_func, s.substr(beg, end - beg), tooltip_ud);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return tt;
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
return Control::get_tooltip(p_pos);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::set_tooltip_request_func(Object *p_obj, const StringName &p_function, const Variant &p_udata) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
tooltip_obj = p_obj;
|
|
|
|
tooltip_func = p_function;
|
|
|
|
tooltip_ud = p_udata;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::set_line(int line, String new_text) {
|
2015-01-02 19:08:40 +01:00
|
|
|
if (line < 0 || line > text.size())
|
|
|
|
return;
|
|
|
|
_remove_text(line, 0, line, text[line].length());
|
|
|
|
_insert_text(line, 0, new_text);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cursor.line == line) {
|
|
|
|
cursor.column = MIN(cursor.column, new_text.length());
|
2015-05-05 05:17:22 +02:00
|
|
|
}
|
2014-11-12 15:39:21 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void TextEdit::insert_at(const String &p_text, int at) {
|
2014-12-07 08:21:49 +01:00
|
|
|
cursor_set_column(0);
|
|
|
|
cursor_set_line(at);
|
2017-03-05 16:44:50 +01:00
|
|
|
_insert_text(at, 0, p_text + "\n");
|
2014-11-12 15:39:21 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void TextEdit::set_show_line_numbers(bool p_show) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
line_numbers = p_show;
|
2015-01-02 19:08:40 +01:00
|
|
|
update();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-10 13:43:09 +02:00
|
|
|
void TextEdit::set_line_numbers_zero_padded(bool p_zero_padded) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
line_numbers_zero_padded = p_zero_padded;
|
2016-10-10 13:43:09 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-07-11 16:11:35 +02:00
|
|
|
bool TextEdit::is_show_line_numbers_enabled() const {
|
|
|
|
return line_numbers;
|
|
|
|
}
|
|
|
|
|
2016-10-10 10:34:51 +02:00
|
|
|
void TextEdit::set_show_line_length_guideline(bool p_show) {
|
2017-03-05 16:44:50 +01:00
|
|
|
line_length_guideline = p_show;
|
2016-10-10 10:34:51 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::set_line_length_guideline_column(int p_column) {
|
2017-03-05 16:44:50 +01:00
|
|
|
line_length_guideline_col = p_column;
|
2016-10-10 10:34:51 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-05-26 15:17:14 +02:00
|
|
|
void TextEdit::set_draw_breakpoint_gutter(bool p_draw) {
|
|
|
|
draw_breakpoint_gutter = p_draw;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TextEdit::is_drawing_breakpoint_gutter() const {
|
|
|
|
return draw_breakpoint_gutter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextEdit::set_breakpoint_gutter_width(int p_gutter_width) {
|
|
|
|
breakpoint_gutter_width = p_gutter_width;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TextEdit::get_breakpoint_gutter_width() const {
|
|
|
|
return cache.breakpoint_gutter_width;
|
|
|
|
}
|
|
|
|
|
2015-10-17 15:29:54 +02:00
|
|
|
bool TextEdit::is_text_field() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return true;
|
2015-10-17 15:29:54 +02:00
|
|
|
}
|
2016-05-17 01:25:17 +02:00
|
|
|
|
|
|
|
void TextEdit::menu_option(int p_option) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_option) {
|
2016-05-17 01:25:17 +02:00
|
|
|
case MENU_CUT: {
|
2016-09-19 14:17:48 +02:00
|
|
|
if (!readonly) {
|
|
|
|
cut();
|
|
|
|
}
|
2016-05-17 01:25:17 +02:00
|
|
|
} break;
|
|
|
|
case MENU_COPY: {
|
|
|
|
copy();
|
|
|
|
} break;
|
|
|
|
case MENU_PASTE: {
|
2016-09-19 14:17:48 +02:00
|
|
|
if (!readonly) {
|
|
|
|
paste();
|
|
|
|
}
|
2016-05-17 01:25:17 +02:00
|
|
|
} break;
|
|
|
|
case MENU_CLEAR: {
|
2016-09-19 14:17:48 +02:00
|
|
|
if (!readonly) {
|
|
|
|
clear();
|
|
|
|
}
|
2016-05-17 01:25:17 +02:00
|
|
|
} break;
|
|
|
|
case MENU_SELECT_ALL: {
|
|
|
|
select_all();
|
|
|
|
} break;
|
|
|
|
case MENU_UNDO: {
|
|
|
|
undo();
|
|
|
|
} break;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-09-12 15:52:29 +02:00
|
|
|
void TextEdit::set_select_identifiers_on_hover(bool p_enable) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
select_identifiers_enabled = p_enable;
|
2016-09-12 15:52:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TextEdit::is_selecting_identifiers_on_hover_enabled() const {
|
|
|
|
|
|
|
|
return select_identifiers_enabled;
|
|
|
|
}
|
|
|
|
|
2016-09-29 09:12:45 +02:00
|
|
|
void TextEdit::set_context_menu_enabled(bool p_enable) {
|
|
|
|
context_menu_enabled = p_enable;
|
|
|
|
}
|
2016-09-12 15:52:29 +02:00
|
|
|
|
2016-05-17 01:25:17 +02:00
|
|
|
PopupMenu *TextEdit::get_menu() const {
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TextEdit::_bind_methods() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_gui_input"), &TextEdit::_gui_input);
|
|
|
|
ClassDB::bind_method(D_METHOD("_scroll_moved"), &TextEdit::_scroll_moved);
|
|
|
|
ClassDB::bind_method(D_METHOD("_cursor_changed_emit"), &TextEdit::_cursor_changed_emit);
|
|
|
|
ClassDB::bind_method(D_METHOD("_text_changed_emit"), &TextEdit::_text_changed_emit);
|
|
|
|
ClassDB::bind_method(D_METHOD("_push_current_op"), &TextEdit::_push_current_op);
|
|
|
|
ClassDB::bind_method(D_METHOD("_click_selection_held"), &TextEdit::_click_selection_held);
|
|
|
|
ClassDB::bind_method(D_METHOD("_toggle_draw_caret"), &TextEdit::_toggle_draw_caret);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
BIND_CONSTANT(SEARCH_MATCH_CASE);
|
|
|
|
BIND_CONSTANT(SEARCH_WHOLE_WORDS);
|
|
|
|
BIND_CONSTANT(SEARCH_BACKWARDS);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
/*
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("delete_char"),&TextEdit::delete_char);
|
|
|
|
ClassDB::bind_method(D_METHOD("delete_line"),&TextEdit::delete_line);
|
2014-02-10 02:10:30 +01:00
|
|
|
*/
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_text", "text"), &TextEdit::set_text);
|
|
|
|
ClassDB::bind_method(D_METHOD("insert_text_at_cursor", "text"), &TextEdit::insert_text_at_cursor);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_line_count"), &TextEdit::get_line_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_text"), &TextEdit::get_text);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_line", "line"), &TextEdit::get_line);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-04-15 19:48:10 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("cursor_set_column", "column", "adjust_viewport"), &TextEdit::cursor_set_column, DEFVAL(true));
|
|
|
|
ClassDB::bind_method(D_METHOD("cursor_set_line", "line", "adjust_viewport"), &TextEdit::cursor_set_line, DEFVAL(true));
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("cursor_get_column"), &TextEdit::cursor_get_column);
|
|
|
|
ClassDB::bind_method(D_METHOD("cursor_get_line"), &TextEdit::cursor_get_line);
|
|
|
|
ClassDB::bind_method(D_METHOD("cursor_set_blink_enabled", "enable"), &TextEdit::cursor_set_blink_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("cursor_get_blink_enabled"), &TextEdit::cursor_get_blink_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("cursor_set_blink_speed", "blink_speed"), &TextEdit::cursor_set_blink_speed);
|
|
|
|
ClassDB::bind_method(D_METHOD("cursor_get_blink_speed"), &TextEdit::cursor_get_blink_speed);
|
2017-02-13 12:47:24 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("cursor_set_block_mode", "enable"), &TextEdit::cursor_set_block_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("cursor_is_block_mode"), &TextEdit::cursor_is_block_mode);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_readonly", "enable"), &TextEdit::set_readonly);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_wrap", "enable"), &TextEdit::set_wrap);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_max_chars", "amount"), &TextEdit::set_max_chars);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("cut"), &TextEdit::cut);
|
|
|
|
ClassDB::bind_method(D_METHOD("copy"), &TextEdit::copy);
|
|
|
|
ClassDB::bind_method(D_METHOD("paste"), &TextEdit::paste);
|
|
|
|
ClassDB::bind_method(D_METHOD("select_all"), &TextEdit::select_all);
|
|
|
|
ClassDB::bind_method(D_METHOD("select", "from_line", "from_column", "to_line", "to_column"), &TextEdit::select);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("is_selection_active"), &TextEdit::is_selection_active);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_selection_from_line"), &TextEdit::get_selection_from_line);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_selection_from_column"), &TextEdit::get_selection_from_column);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_selection_to_line"), &TextEdit::get_selection_to_line);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_selection_to_column"), &TextEdit::get_selection_to_column);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_selection_text"), &TextEdit::get_selection_text);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_word_under_cursor"), &TextEdit::get_word_under_cursor);
|
|
|
|
ClassDB::bind_method(D_METHOD("search", "flags", "from_line", "from_column", "to_line", "to_column"), &TextEdit::_search_bind);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("undo"), &TextEdit::undo);
|
|
|
|
ClassDB::bind_method(D_METHOD("redo"), &TextEdit::redo);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_undo_history"), &TextEdit::clear_undo_history);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_show_line_numbers", "enable"), &TextEdit::set_show_line_numbers);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_show_line_numbers_enabled"), &TextEdit::is_show_line_numbers_enabled);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_highlight_all_occurrences", "enable"), &TextEdit::set_highlight_all_occurrences);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_highlight_all_occurrences_enabled"), &TextEdit::is_highlight_all_occurrences_enabled);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_syntax_coloring", "enable"), &TextEdit::set_syntax_coloring);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_syntax_coloring_enabled"), &TextEdit::is_syntax_coloring_enabled);
|
2017-02-13 12:47:24 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("add_keyword_color", "keyword", "color"), &TextEdit::add_keyword_color);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_color_region", "begin_key", "end_key", "color", "line_only"), &TextEdit::add_color_region, DEFVAL(false));
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_colors"), &TextEdit::clear_colors);
|
|
|
|
ClassDB::bind_method(D_METHOD("menu_option"), &TextEdit::menu_option);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_menu:PopupMenu"), &TextEdit::get_menu);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-02-12 01:11:37 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "syntax_highlighting"), "set_syntax_coloring", "is_syntax_coloring_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_line_numbers"), "set_show_line_numbers", "is_show_line_numbers_enabled");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_all_occurrences"), "set_highlight_all_occurrences", "is_highlight_all_occurrences_enabled");
|
2016-07-11 16:11:35 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_GROUP("Caret", "caret_");
|
2017-02-12 01:11:37 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_block_mode"), "cursor_set_block_mode", "cursor_is_block_mode");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "cursor_set_blink_enabled", "cursor_get_blink_enabled");
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.1"), "cursor_set_blink_speed", "cursor_get_blink_speed");
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("cursor_changed"));
|
|
|
|
ADD_SIGNAL(MethodInfo("text_changed"));
|
|
|
|
ADD_SIGNAL(MethodInfo("request_completion"));
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("breakpoint_toggled", PropertyInfo(Variant::INT, "row")));
|
|
|
|
ADD_SIGNAL(MethodInfo("symbol_lookup", PropertyInfo(Variant::STRING, "symbol"), PropertyInfo(Variant::INT, "row"), PropertyInfo(Variant::INT, "column")));
|
2016-05-17 01:25:17 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
BIND_CONSTANT(MENU_CUT);
|
|
|
|
BIND_CONSTANT(MENU_COPY);
|
|
|
|
BIND_CONSTANT(MENU_PASTE);
|
|
|
|
BIND_CONSTANT(MENU_CLEAR);
|
|
|
|
BIND_CONSTANT(MENU_SELECT_ALL);
|
|
|
|
BIND_CONSTANT(MENU_UNDO);
|
|
|
|
BIND_CONSTANT(MENU_MAX);
|
2016-05-17 01:25:17 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GLOBAL_DEF("gui/timers/text_edit_idle_detect_sec", 3);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
TextEdit::TextEdit() {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
readonly = false;
|
|
|
|
setting_row = false;
|
|
|
|
draw_tabs = false;
|
|
|
|
draw_caret = true;
|
|
|
|
max_chars = 0;
|
2015-01-02 19:08:40 +01:00
|
|
|
clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
wrap = false;
|
2015-01-02 19:08:40 +01:00
|
|
|
set_focus_mode(FOCUS_ALL);
|
|
|
|
_update_caches();
|
2017-03-05 16:44:50 +01:00
|
|
|
cache.size = Size2(1, 1);
|
|
|
|
cache.row_height = 1;
|
|
|
|
cache.line_spacing = 1;
|
|
|
|
cache.line_number_w = 1;
|
|
|
|
cache.breakpoint_gutter_width = 0;
|
2016-05-26 15:17:14 +02:00
|
|
|
breakpoint_gutter_width = 0;
|
2015-06-07 03:06:58 +02:00
|
|
|
|
2017-04-17 15:24:30 +02:00
|
|
|
indent_size = 4;
|
|
|
|
text.set_indent_size(indent_size);
|
2015-01-02 19:08:40 +01:00
|
|
|
text.clear();
|
2017-01-14 12:26:56 +01:00
|
|
|
//text.insert(1,"Mongolia..");
|
|
|
|
//text.insert(2,"PAIS GENEROSO!!");
|
2015-01-02 19:08:40 +01:00
|
|
|
text.set_color_regions(&color_regions);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
h_scroll = memnew(HScrollBar);
|
|
|
|
v_scroll = memnew(VScrollBar);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
add_child(h_scroll);
|
|
|
|
add_child(v_scroll);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
updating_scrolls = false;
|
|
|
|
selection.active = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
h_scroll->connect("value_changed", this, "_scroll_moved");
|
|
|
|
v_scroll->connect("value_changed", this, "_scroll_moved");
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor_changed_dirty = false;
|
|
|
|
text_changed_dirty = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
selection.selecting_mode = Selection::MODE_NONE;
|
|
|
|
selection.selecting_line = 0;
|
|
|
|
selection.selecting_column = 0;
|
|
|
|
selection.selecting_text = false;
|
|
|
|
selection.active = false;
|
|
|
|
syntax_coloring = false;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
block_caret = false;
|
|
|
|
caret_blink_enabled = false;
|
2016-05-09 20:21:55 +02:00
|
|
|
caret_blink_timer = memnew(Timer);
|
|
|
|
add_child(caret_blink_timer);
|
|
|
|
caret_blink_timer->set_wait_time(0.65);
|
2017-03-05 16:44:50 +01:00
|
|
|
caret_blink_timer->connect("timeout", this, "_toggle_draw_caret");
|
2016-05-09 20:21:55 +02:00
|
|
|
cursor_set_blink_enabled(false);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
idle_detect = memnew(Timer);
|
2015-01-02 19:08:40 +01:00
|
|
|
add_child(idle_detect);
|
|
|
|
idle_detect->set_one_shot(true);
|
2017-01-05 13:16:00 +01:00
|
|
|
idle_detect->set_wait_time(GLOBAL_GET("gui/timers/text_edit_idle_detect_sec"));
|
2017-03-05 16:44:50 +01:00
|
|
|
idle_detect->connect("timeout", this, "_push_current_op");
|
2015-12-09 19:56:41 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
click_select_held = memnew(Timer);
|
2015-12-09 19:56:41 +01:00
|
|
|
add_child(click_select_held);
|
|
|
|
click_select_held->set_wait_time(0.05);
|
2017-03-05 16:44:50 +01:00
|
|
|
click_select_held->connect("timeout", this, "_click_selection_held");
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#if 0
|
2015-01-02 19:08:40 +01:00
|
|
|
syntax_coloring=true;
|
|
|
|
keywords["void"]=Color(0.3,0.0,0.1);
|
|
|
|
keywords["int"]=Color(0.3,0.0,0.1);
|
|
|
|
keywords["function"]=Color(0.3,0.0,0.1);
|
|
|
|
keywords["class"]=Color(0.3,0.0,0.1);
|
|
|
|
keywords["extends"]=Color(0.3,0.0,0.1);
|
|
|
|
keywords["constructor"]=Color(0.3,0.0,0.1);
|
|
|
|
symbol_color=Color(0.1,0.0,0.3,1.0);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2015-01-02 19:08:40 +01:00
|
|
|
color_regions.push_back(ColorRegion("/*","*/",Color(0.4,0.6,0,4)));
|
|
|
|
color_regions.push_back(ColorRegion("//","",Color(0.6,0.6,0.4)));
|
|
|
|
color_regions.push_back(ColorRegion("\"","\"",Color(0.4,0.7,0.7)));
|
|
|
|
color_regions.push_back(ColorRegion("'","'",Color(0.4,0.8,0.8)));
|
|
|
|
color_regions.push_back(ColorRegion("#","",Color(0.2,1.0,0.2)));
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
current_op.type = TextOperation::TYPE_NONE;
|
|
|
|
undo_enabled = true;
|
|
|
|
undo_stack_pos = NULL;
|
|
|
|
setting_text = false;
|
|
|
|
last_dblclk = 0;
|
|
|
|
current_op.version = 0;
|
|
|
|
version = 0;
|
|
|
|
saved_version = 0;
|
|
|
|
|
|
|
|
completion_enabled = false;
|
|
|
|
completion_active = false;
|
|
|
|
completion_line_ofs = 0;
|
|
|
|
tooltip_obj = NULL;
|
|
|
|
line_numbers = false;
|
|
|
|
line_numbers_zero_padded = false;
|
|
|
|
line_length_guideline = false;
|
|
|
|
line_length_guideline_col = 80;
|
|
|
|
draw_breakpoint_gutter = false;
|
|
|
|
next_operation_is_complex = false;
|
|
|
|
scroll_past_end_of_file_enabled = false;
|
|
|
|
auto_brace_completion_enabled = false;
|
|
|
|
brace_matching_enabled = false;
|
|
|
|
highlight_all_occurrences = false;
|
2017-04-17 15:24:30 +02:00
|
|
|
indent_using_spaces = false;
|
|
|
|
space_indent = " ";
|
2017-03-05 16:44:50 +01:00
|
|
|
auto_indent = false;
|
2016-03-31 21:49:30 +02:00
|
|
|
insert_mode = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
window_has_focus = true;
|
|
|
|
select_identifiers_enabled = false;
|
2016-05-17 01:25:17 +02:00
|
|
|
|
2016-10-10 13:21:37 +02:00
|
|
|
raised_from_completion = false;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
context_menu_enabled = true;
|
|
|
|
menu = memnew(PopupMenu);
|
2016-05-17 01:25:17 +02:00
|
|
|
add_child(menu);
|
2017-03-05 16:44:50 +01:00
|
|
|
menu->add_item(TTR("Cut"), MENU_CUT, KEY_MASK_CMD | KEY_X);
|
|
|
|
menu->add_item(TTR("Copy"), MENU_COPY, KEY_MASK_CMD | KEY_C);
|
|
|
|
menu->add_item(TTR("Paste"), MENU_PASTE, KEY_MASK_CMD | KEY_V);
|
2016-05-17 01:25:17 +02:00
|
|
|
menu->add_separator();
|
2017-03-05 16:44:50 +01:00
|
|
|
menu->add_item(TTR("Select All"), MENU_SELECT_ALL, KEY_MASK_CMD | KEY_A);
|
|
|
|
menu->add_item(TTR("Clear"), MENU_CLEAR);
|
2016-05-17 01:25:17 +02:00
|
|
|
menu->add_separator();
|
2017-03-05 16:44:50 +01:00
|
|
|
menu->add_item(TTR("Undo"), MENU_UNDO, KEY_MASK_CMD | KEY_Z);
|
|
|
|
menu->connect("id_pressed", this, "menu_option");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
TextEdit::~TextEdit() {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|