mirror of https://github.com/buggins/dlangui.git
editor content enhancements
This commit is contained in:
parent
37194b81b2
commit
ec31e0838c
|
@ -219,6 +219,14 @@ struct Signal(T1) if (is(T1 == interface) && __traits(allMembers, T1).length ==
|
||||||
final void disconnect(slot_t listener) {
|
final void disconnect(slot_t listener) {
|
||||||
_listeners -= listener;
|
_listeners -= listener;
|
||||||
}
|
}
|
||||||
|
/// add listener - as interface member
|
||||||
|
final void connect(T1 listener) {
|
||||||
|
connect(&__traits(getMember, listener, __traits(allMembers, T1)[0]));
|
||||||
|
}
|
||||||
|
/// add listener - as interface member
|
||||||
|
final void disconnect(T1 listener) {
|
||||||
|
disconnect(&__traits(getMember, listener, __traits(allMembers, T1)[0]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Multiple listeners; implicitly specified return and parameter types
|
/// Multiple listeners; implicitly specified return and parameter types
|
||||||
|
|
|
@ -725,6 +725,38 @@ class EditWidgetBase : WidgetGroup, EditableContentListener {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// editor content object
|
||||||
|
@property EditableContent content() {
|
||||||
|
return _content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// when _ownContent is false, _content should not be destroyed in editor destructor
|
||||||
|
protected bool _ownContent = true;
|
||||||
|
/// set content object
|
||||||
|
@property EditWidgetBase content(EditableContent content) {
|
||||||
|
if (_content is content)
|
||||||
|
return this; // not changed
|
||||||
|
if (_content !is null) {
|
||||||
|
// disconnect old content
|
||||||
|
_content.contentChangeListeners.disconnect(this);
|
||||||
|
if (_ownContent) {
|
||||||
|
destroy(_content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_content = content;
|
||||||
|
_ownContent = false;
|
||||||
|
_content.contentChangeListeners.connect(this);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// free resources
|
||||||
|
~this() {
|
||||||
|
if (_ownContent) {
|
||||||
|
destroy(_content);
|
||||||
|
_content = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void updateMaxLineWidth() {
|
protected void updateMaxLineWidth() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -813,16 +845,26 @@ class EditWidgetBase : WidgetGroup, EditableContentListener {
|
||||||
protected void updateScrollbars() {
|
protected void updateScrollbars() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// when position is out of content bounds, fix it to nearest valid position
|
||||||
|
protected void correctPosition(ref TextPosition position) {
|
||||||
|
if (position.line >= _content.length)
|
||||||
|
position.line = _content.length - 1;
|
||||||
|
if (position.line < 0)
|
||||||
|
position.line = 0;
|
||||||
|
dstring currentLine = _content[position.line];
|
||||||
|
if (position.pos > currentLine.length)
|
||||||
|
position.pos = cast(int)currentLine.length;
|
||||||
|
if (position.pos < 0)
|
||||||
|
position.pos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// when cursor position or selection is out of content bounds, fix it to nearest valid position
|
||||||
protected void correctCaretPos() {
|
protected void correctCaretPos() {
|
||||||
if (_caretPos.line >= _content.length)
|
correctPosition(_caretPos);
|
||||||
_caretPos.line = _content.length - 1;
|
correctPosition(_selectionRange.start);
|
||||||
if (_caretPos.line < 0)
|
correctPosition(_selectionRange.end);
|
||||||
_caretPos.line = 0;
|
if (_selectionRange.empty)
|
||||||
dstring currentLine = _content[_caretPos.line];
|
_selectionRange = TextRange(_caretPos, _caretPos);
|
||||||
if (_caretPos.pos > currentLine.length)
|
|
||||||
_caretPos.pos = cast(int)currentLine.length;
|
|
||||||
if (_caretPos.pos < 0)
|
|
||||||
_caretPos.pos = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue