mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 21:47:00 -04:00
symmetric selection handling
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@240 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+12
-4
@@ -563,6 +563,13 @@ void TextValueEditor::moveSelectionNoRedraw(IndexType t, size_t new_end, bool al
|
|||||||
fixSelection(t, dir);
|
fixSelection(t, dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// direction of a with respect to b
|
||||||
|
Movement direction_of(size_t a, size_t b) {
|
||||||
|
if (a < b) return MOVE_LEFT_OPT;
|
||||||
|
if (a > b) return MOVE_RIGHT_OPT;
|
||||||
|
else return MOVE_MID;
|
||||||
|
}
|
||||||
|
|
||||||
void TextValueEditor::fixSelection(IndexType t, Movement dir) {
|
void TextValueEditor::fixSelection(IndexType t, Movement dir) {
|
||||||
const String& val = value().value();
|
const String& val = value().value();
|
||||||
// Which type takes precedent?
|
// Which type takes precedent?
|
||||||
@@ -571,8 +578,9 @@ void TextValueEditor::fixSelection(IndexType t, Movement dir) {
|
|||||||
selection_end = index_to_cursor(value().value(), selection_end_i, dir);
|
selection_end = index_to_cursor(value().value(), selection_end_i, dir);
|
||||||
}
|
}
|
||||||
// make sure the selection is at a valid position inside the text
|
// make sure the selection is at a valid position inside the text
|
||||||
selection_start_i = cursor_to_index(val, selection_start, selection_start == selection_end ? MOVE_MID : MOVE_RIGHT_OPT);
|
// prepare to move 'inward' (i.e. from start in the direction of end and vice versa)
|
||||||
selection_end_i = cursor_to_index(val, selection_end, selection_start == selection_end ? MOVE_MID : MOVE_LEFT_OPT);
|
selection_start_i = cursor_to_index(val, selection_start, direction_of(selection_end, selection_start));
|
||||||
|
selection_end_i = cursor_to_index(val, selection_end, direction_of(selection_start, selection_end));
|
||||||
// start and end must be on the same side of separators
|
// start and end must be on the same side of separators
|
||||||
size_t seppos = val.find(_("<sep"));
|
size_t seppos = val.find(_("<sep"));
|
||||||
while (seppos != String::npos) {
|
while (seppos != String::npos) {
|
||||||
@@ -580,11 +588,11 @@ void TextValueEditor::fixSelection(IndexType t, Movement dir) {
|
|||||||
if (selection_start_i <= seppos && selection_end_i > seppos) {
|
if (selection_start_i <= seppos && selection_end_i > seppos) {
|
||||||
// not on same side, move selection end before sep
|
// not on same side, move selection end before sep
|
||||||
selection_end = index_to_cursor(val, seppos, dir);
|
selection_end = index_to_cursor(val, seppos, dir);
|
||||||
selection_end_i = cursor_to_index(val, selection_end, selection_start == selection_end ? MOVE_MID : MOVE_LEFT_OPT);
|
selection_end_i = cursor_to_index(val, selection_end, direction_of(selection_start, selection_end));
|
||||||
} else if (selection_start_i >= sepend && selection_end_i < sepend) {
|
} else if (selection_start_i >= sepend && selection_end_i < sepend) {
|
||||||
// not on same side, move selection end after sep
|
// not on same side, move selection end after sep
|
||||||
selection_end = index_to_cursor(val, sepend, dir);
|
selection_end = index_to_cursor(val, sepend, dir);
|
||||||
selection_end_i = cursor_to_index(val, selection_end, selection_start == selection_end ? MOVE_MID : MOVE_LEFT_OPT);
|
selection_end_i = cursor_to_index(val, selection_end, direction_of(selection_start, selection_end));
|
||||||
}
|
}
|
||||||
// find next separator
|
// find next separator
|
||||||
seppos = val.find(_("<sep"), seppos + 1);
|
seppos = val.find(_("<sep"), seppos + 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user