editors refactoring

This commit is contained in:
Vadim Lopatin 2014-04-22 17:00:57 +04:00
parent 28774a9ba6
commit a5aaa1a9cc
1 changed files with 15 additions and 20 deletions

View File

@ -435,7 +435,20 @@ class EditWidgetBase : WidgetGroup, EditableContentListener {
]);
}
abstract override bool onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter);
protected void updateMaxLineWidth() {
}
override bool onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter) {
updateMaxLineWidth();
measureVisibleText();
_caretPos = rangeAfter.end;
_selectionRange.start = _caretPos;
_selectionRange.end = _caretPos;
ensureCaretVisible();
invalidate();
return true;
}
/// get widget text
override @property dstring text() { return _content.text; }
@ -621,13 +634,6 @@ class EditLine : EditWidgetBase {
text = initialContent;
}
override bool onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter) {
measureVisibleText();
_caretPos = rangeAfter.end;
invalidate();
return true;
}
protected dstring _measuredText;
protected int[] _measuredTextWidths;
protected Point _measuredTextSize;
@ -834,7 +840,7 @@ class EditBox : EditWidgetBase, OnScrollHandler {
protected int[][] _visibleLinesMeasurement; // char positions for visible lines
protected int[] _visibleLinesWidths; // width (in pixels) of visible lines
protected void updateMaxLineWidth() {
override protected void updateMaxLineWidth() {
// find max line width. TODO: optimize!!!
int maxw;
int[] buf;
@ -937,17 +943,6 @@ class EditBox : EditWidgetBase, OnScrollHandler {
updateScrollbars();
}
override bool onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter) {
updateMaxLineWidth();
measureVisibleText();
_caretPos = rangeAfter.end;
_selectionRange.start = _caretPos;
_selectionRange.end = _caretPos;
ensureCaretVisible();
invalidate();
return true;
}
override protected Rect textPosToClient(TextPosition p) {
Rect res;
int lineIndex = p.line - _firstVisibleLine;