-void Editor::LineSelection(int lineCurrent_, int lineAnchor_) {
- if (lineAnchor_ < lineCurrent_) {
- SetSelection(pdoc->LineStart(lineCurrent_ + 1),
- pdoc->LineStart(lineAnchor_));
- } else if (lineAnchor_ > lineCurrent_) {
- SetSelection(pdoc->LineStart(lineCurrent_),
- pdoc->LineStart(lineAnchor_ + 1));
- } else { // Same line, select it
- SetSelection(pdoc->LineStart(lineAnchor_ + 1),
- pdoc->LineStart(lineAnchor_));
+Window::Cursor Editor::GetMarginCursor(Point pt) {
+ int x = 0;
+ for (int margin = 0; margin < ViewStyle::margins; margin++) {
+ if ((pt.x >= x) && (pt.x < x + vs.ms[margin].width))
+ return static_cast<Window::Cursor>(vs.ms[margin].cursor);
+ x += vs.ms[margin].width;
+ }
+ return Window::cursorReverseArrow;
+}
+
+void Editor::TrimAndSetSelection(int currentPos_, int anchor_) {
+ sel.TrimSelection(SelectionRange(currentPos_, anchor_));
+ SetSelection(currentPos_, anchor_);
+}
+
+void Editor::LineSelection(int lineCurrentPos_, int lineAnchorPos_, bool wholeLine) {
+ int selCurrentPos, selAnchorPos;
+ if (wholeLine) {
+ int lineCurrent_ = pdoc->LineFromPosition(lineCurrentPos_);
+ int lineAnchor_ = pdoc->LineFromPosition(lineAnchorPos_);
+ if (lineAnchorPos_ < lineCurrentPos_) {
+ selCurrentPos = pdoc->LineStart(lineCurrent_ + 1);
+ selAnchorPos = pdoc->LineStart(lineAnchor_);
+ } else if (lineAnchorPos_ > lineCurrentPos_) {
+ selCurrentPos = pdoc->LineStart(lineCurrent_);
+ selAnchorPos = pdoc->LineStart(lineAnchor_ + 1);
+ } else { // Same line, select it
+ selCurrentPos = pdoc->LineStart(lineAnchor_ + 1);
+ selAnchorPos = pdoc->LineStart(lineAnchor_);
+ }
+ } else {
+ if (lineAnchorPos_ < lineCurrentPos_) {
+ selCurrentPos = StartEndDisplayLine(lineCurrentPos_, false) + 1;
+ selCurrentPos = pdoc->MovePositionOutsideChar(selCurrentPos, 1);
+ selAnchorPos = StartEndDisplayLine(lineAnchorPos_, true);
+ } else if (lineAnchorPos_ > lineCurrentPos_) {
+ selCurrentPos = StartEndDisplayLine(lineCurrentPos_, true);
+ selAnchorPos = StartEndDisplayLine(lineAnchorPos_, false) + 1;
+ selAnchorPos = pdoc->MovePositionOutsideChar(selAnchorPos, 1);
+ } else { // Same line, select it
+ selCurrentPos = StartEndDisplayLine(lineAnchorPos_, false) + 1;
+ selCurrentPos = pdoc->MovePositionOutsideChar(selCurrentPos, 1);
+ selAnchorPos = StartEndDisplayLine(lineAnchorPos_, true);
+ }
+ }
+ TrimAndSetSelection(selCurrentPos, selAnchorPos);
+}
+
+void Editor::WordSelection(int pos) {
+ if (pos < wordSelectAnchorStartPos) {
+ // Extend backward to the word containing pos.
+ // Skip ExtendWordSelect if the line is empty or if pos is after the last character.
+ // This ensures that a series of empty lines isn't counted as a single "word".
+ if (!pdoc->IsLineEndPosition(pos))
+ pos = pdoc->ExtendWordSelect(pdoc->MovePositionOutsideChar(pos + 1, 1), -1);
+ TrimAndSetSelection(pos, wordSelectAnchorEndPos);
+ } else if (pos > wordSelectAnchorEndPos) {
+ // Extend forward to the word containing the character to the left of pos.
+ // Skip ExtendWordSelect if the line is empty or if pos is the first position on the line.
+ // This ensures that a series of empty lines isn't counted as a single "word".
+ if (pos > pdoc->LineStart(pdoc->LineFromPosition(pos)))
+ pos = pdoc->ExtendWordSelect(pdoc->MovePositionOutsideChar(pos - 1, -1), 1);
+ TrimAndSetSelection(pos, wordSelectAnchorStartPos);
+ } else {
+ // Select only the anchored word
+ if (pos >= originalAnchorPos)
+ TrimAndSetSelection(wordSelectAnchorEndPos, wordSelectAnchorStartPos);
+ else
+ TrimAndSetSelection(wordSelectAnchorStartPos, wordSelectAnchorEndPos);