mirror of https://github.com/buggins/dlangui.git
shift+tab to remove space before cursor or selection
This commit is contained in:
parent
2473a3f604
commit
9fb9a451d4
|
@ -1025,12 +1025,33 @@ class EditWidgetBase : WidgetGroup, EditableContentListener {
|
||||||
{
|
{
|
||||||
if (_selectionRange.empty) {
|
if (_selectionRange.empty) {
|
||||||
// remove spaces before caret
|
// remove spaces before caret
|
||||||
|
TextRange r = spaceBefore(_caretPos);
|
||||||
|
if (!r.empty) {
|
||||||
|
EditOperation op = new EditOperation(EditAction.Replace, r, [""d]);
|
||||||
|
_content.performOperation(op);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (wholeLinesSelected()) {
|
if (wholeLinesSelected()) {
|
||||||
// unindent range
|
// unindent range
|
||||||
indentRange(true);
|
indentRange(true);
|
||||||
} else {
|
} else {
|
||||||
// remove space before selection
|
// remove space before selection
|
||||||
|
TextRange r = spaceBefore(_selectionRange.start);
|
||||||
|
if (!r.empty) {
|
||||||
|
int nchars = r.end.pos - r.start.pos;
|
||||||
|
TextRange saveRange = _selectionRange;
|
||||||
|
TextPosition saveCursor = _caretPos;
|
||||||
|
EditOperation op = new EditOperation(EditAction.Replace, r, [""d]);
|
||||||
|
_content.performOperation(op);
|
||||||
|
if (saveCursor.line == saveRange.start.line)
|
||||||
|
saveCursor.pos -= nchars;
|
||||||
|
if (saveRange.end.line == saveRange.start.line)
|
||||||
|
saveRange.end.pos -= nchars;
|
||||||
|
saveRange.start.pos -= nchars;
|
||||||
|
_selectionRange = saveRange;
|
||||||
|
_caretPos = saveCursor;
|
||||||
|
ensureCaretVisible();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1041,6 +1062,32 @@ class EditWidgetBase : WidgetGroup, EditableContentListener {
|
||||||
return super.handleAction(a);
|
return super.handleAction(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected TextRange spaceBefore(TextPosition pos) {
|
||||||
|
TextRange res = TextRange(pos, pos);
|
||||||
|
dstring s = _content[pos.line];
|
||||||
|
int x = 0;
|
||||||
|
int start = -1;
|
||||||
|
for (int i = 0; i < pos.pos; i++) {
|
||||||
|
dchar ch = s[i];
|
||||||
|
if (ch == ' ') {
|
||||||
|
if (start == -1 || (x % tabSize) == 0)
|
||||||
|
start = i;
|
||||||
|
x++;
|
||||||
|
} else if (ch == '\t') {
|
||||||
|
if (start == -1 || (x % tabSize) == 0)
|
||||||
|
start = i;
|
||||||
|
x = (x + tabSize + 1) / tabSize * tabSize;
|
||||||
|
} else {
|
||||||
|
x++;
|
||||||
|
start = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (start != -1) {
|
||||||
|
res.start.pos = start;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/// change line indent
|
/// change line indent
|
||||||
protected dstring indentLine(dstring src, bool back) {
|
protected dstring indentLine(dstring src, bool back) {
|
||||||
int firstNonSpace = -1;
|
int firstNonSpace = -1;
|
||||||
|
|
Loading…
Reference in New Issue