diff options
| -rw-r--r-- | include/Scintilla.h | 8 | ||||
| -rw-r--r-- | include/Scintilla.iface | 26 | ||||
| -rw-r--r-- | src/Document.cxx | 34 | ||||
| -rw-r--r-- | src/Document.h | 1 | ||||
| -rw-r--r-- | src/Editor.cxx | 78 | ||||
| -rw-r--r-- | src/Editor.h | 2 | 
6 files changed, 144 insertions, 5 deletions
diff --git a/include/Scintilla.h b/include/Scintilla.h index 048aac311..d0b788e47 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -559,6 +559,14 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,  #define SCI_LINEENDRECTEXTEND 2432  #define SCI_PAGEUPRECTEXTEND 2433  #define SCI_PAGEDOWNRECTEXTEND 2434 +#define SCI_STUTTEREDPAGEUP 2435 +#define SCI_STUTTEREDPAGEUPEXTEND 2436 +#define SCI_STUTTEREDPAGEDOWN 2437 +#define SCI_STUTTEREDPAGEDOWNEXTEND 2438 +#define SCI_WORDLEFTEND 2439 +#define SCI_WORDLEFTENDEXTEND 2440 +#define SCI_WORDRIGHTEND 2441 +#define SCI_WORDRIGHTENDEXTEND 2442  #define SCI_STARTRECORD 3001  #define SCI_STOPRECORD 3002  #define SCI_SETLEXER 4001 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 5aea37875..1e4d0db34 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1513,6 +1513,32 @@ fun void PageUpRectExtend=2433(,)  fun void PageDownRectExtend=2434(,) +# Move caret to top of page, or one page up if already at top of page. +fun void StutteredPageUp=2435(,) + +# Move caret to top of page, or one page up if already at top of page, extending selection to new caret position. +fun void StutteredPageUpExtend=2436(,) + +# Move caret to bottom of page, or one page down if already at bottom of page. +fun void StutteredPageDown=2437(,) + +# Move caret to bottom of page, or one page down if already at bottom of page, extending selection to new caret position. +fun void StutteredPageDownExtend=2438(,) + + +# Move caret left one word, position cursor at end of word. +fun void WordLeftEnd=2439(,) + +# Move caret left one word, position cursor at end of word, extending selection to new caret position. +fun void WordLeftEndExtend=2440(,) + +# Move caret right one word, position cursor at end of word. +fun void WordRightEnd=2441(,) + +# Move caret right one word, position cursor at end of word, extending selection to new caret position. +fun void WordRightEndExtend=2442(,) + +  # Start notifying the container of all key presses and commands.  fun void StartRecord=3001(,) diff --git a/src/Document.cxx b/src/Document.cxx index 7f4893711..130a920e1 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -792,6 +792,40 @@ int Document::NextWordStart(int pos, int delta) {  }  /** + * Find the end of the next word in either a forward (delta >= 0) or backwards direction + * (delta < 0). + * This is looking for a transition between character classes although there is also some + * additional movement to transit white space. + * Used by cursor movement by word commands. + */ +int Document::NextWordEnd(int pos, int delta) { +	if (delta < 0) { +		if (pos > 0) { +			charClassification ccStart = WordCharClass(cb.CharAt(pos-1)); +			if (ccStart != ccSpace) { +				while (pos > 0 && WordCharClass(cb.CharAt(pos - 1)) == ccStart) { +					pos--; +				} +			} +			while (pos > 0 && WordCharClass(cb.CharAt(pos - 1)) == ccSpace) { +				pos--; +			} +		} +	} else { +		while (pos < Length() && WordCharClass(cb.CharAt(pos)) == ccSpace) { +			pos++; +		} +		if (pos < Length()) { +			charClassification ccStart = WordCharClass(cb.CharAt(pos)); +			while (pos < Length() && WordCharClass(cb.CharAt(pos)) == ccStart) { +				pos++; +			} +		} +	} +	return pos; +} + +/**   * Check that the character at the given position is a word or punctuation character and that   * the previous character is of a different character class.   */ diff --git a/src/Document.h b/src/Document.h index 4b44655f3..f811bf077 100644 --- a/src/Document.h +++ b/src/Document.h @@ -190,6 +190,7 @@ public:  	void Indent(bool forwards);  	int ExtendWordSelect(int pos, int delta, bool onlyWordCharacters=false);  	int NextWordStart(int pos, int delta); +	int NextWordEnd(int pos, int delta);  	int Length() { return cb.Length(); }  	long FindText(int minPos, int maxPos, const char *s,  		bool caseSensitive, bool word, bool wordStart, bool regExp, bool posix, int *length); diff --git a/src/Editor.cxx b/src/Editor.cxx index 235821748..06ca56366 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -3593,6 +3593,10 @@ void Editor::NotifyMacroRecord(unsigned int iMessage, unsigned long wParam, long  	case SCI_WORDPARTLEFTEXTEND:  	case SCI_WORDPARTRIGHT:  	case SCI_WORDPARTRIGHTEXTEND: +	case SCI_WORDLEFTEND: +	case SCI_WORDLEFTENDEXTEND: +	case SCI_WORDRIGHTEND: +	case SCI_WORDRIGHTENDEXTEND:  	case SCI_HOME:  	case SCI_HOMEEXTEND:  	case SCI_LINEEND: @@ -3605,6 +3609,10 @@ void Editor::NotifyMacroRecord(unsigned int iMessage, unsigned long wParam, long  	case SCI_DOCUMENTSTARTEXTEND:  	case SCI_DOCUMENTEND:  	case SCI_DOCUMENTENDEXTEND: +	case SCI_STUTTEREDPAGEUP: +	case SCI_STUTTEREDPAGEUPEXTEND: +	case SCI_STUTTEREDPAGEDOWN: +	case SCI_STUTTEREDPAGEDOWNEXTEND:  	case SCI_PAGEUP:  	case SCI_PAGEUPEXTEND:  	case SCI_PAGEDOWN: @@ -3668,13 +3676,35 @@ void Editor::NotifyMacroRecord(unsigned int iMessage, unsigned long wParam, long  /**   * Force scroll and keep position relative to top of window. + * + * If stuttered = true and not already at first/last row, move to first/last row of window. + * If stuttered = true and already at first/last row, scroll as normal.   */ -void Editor::PageMove(int direction, selTypes sel) { -	Point pt = LocationFromPosition(currentPos); -	int topLineNew = Platform::Clamp( +void Editor::PageMove(int direction, selTypes sel, bool stuttered) { +	int topLineNew, newPos; + +	// I consider only the caretYSlop, and ignore the caretYPolicy-- is that a problem? +	int currentLine = pdoc->LineFromPosition(currentPos); +	int topStutterLine = topLine + caretYSlop; +	int bottomStutterLine = topLine + LinesToScroll() - caretYSlop; + +	if (stuttered && (direction < 0 && currentLine > topStutterLine)) { +		topLineNew = topLine; +		newPos = PositionFromLocation(Point(lastXChosen, vs.lineHeight * caretYSlop)); + +	} else if (stuttered && (direction > 0 && currentLine < bottomStutterLine)) { +		topLineNew = topLine; +		newPos = PositionFromLocation(Point(lastXChosen, vs.lineHeight * (LinesToScroll() - caretYSlop))); + +	} else { +		Point pt = LocationFromPosition(currentPos); + +		topLineNew = Platform::Clamp(  	                     topLine + direction * LinesToScroll(), 0, MaxScrollPos()); -	int newPos = PositionFromLocation( +		newPos = PositionFromLocation(  	                 Point(lastXChosen, pt.y + direction * (vs.lineHeight * LinesToScroll()))); +	} +  	if (topLineNew != topLine) {  		SetTopLine(topLineNew);  		MovePositionTo(newPos, sel); @@ -3910,6 +3940,24 @@ int Editor::KeyCommand(unsigned int iMessage) {  		MovePositionTo(MovePositionSoVisible(pdoc->NextWordStart(currentPos, 1), 1), selStream);  		SetLastXChosen();  		break; + +	case SCI_WORDLEFTEND: +		MovePositionTo(MovePositionSoVisible(pdoc->NextWordEnd(currentPos, -1), -1)); +		SetLastXChosen(); +		break; +	case SCI_WORDLEFTENDEXTEND: +		MovePositionTo(MovePositionSoVisible(pdoc->NextWordEnd(currentPos, -1), -1), selStream); +		SetLastXChosen(); +		break; +	case SCI_WORDRIGHTEND: +		MovePositionTo(MovePositionSoVisible(pdoc->NextWordEnd(currentPos, 1), 1)); +		SetLastXChosen(); +		break; +	case SCI_WORDRIGHTENDEXTEND: +		MovePositionTo(MovePositionSoVisible(pdoc->NextWordEnd(currentPos, 1), 1), selStream); +		SetLastXChosen(); +		break; +  	case SCI_HOME:  		MovePositionTo(pdoc->LineStart(pdoc->LineFromPosition(currentPos)));  		SetLastXChosen(); @@ -3982,6 +4030,18 @@ int Editor::KeyCommand(unsigned int iMessage) {  		MovePositionTo(pdoc->Length(), selStream);  		SetLastXChosen();  		break; +	case SCI_STUTTEREDPAGEUP: +		PageMove(-1, noSel, true); +		break; +	case SCI_STUTTEREDPAGEUPEXTEND: +		PageMove(-1, selStream, true); +		break; +	case SCI_STUTTEREDPAGEDOWN: +		PageMove(1, noSel, true); +		break; +	case SCI_STUTTEREDPAGEDOWNEXTEND: +		PageMove(1, selStream, true); +		break;  	case SCI_PAGEUP:  		PageMove(-1);  		break; @@ -6455,6 +6515,10 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {  	case SCI_WORDLEFTEXTEND:  	case SCI_WORDRIGHT:  	case SCI_WORDRIGHTEXTEND: +	case SCI_WORDLEFTEND: +	case SCI_WORDLEFTENDEXTEND: +	case SCI_WORDRIGHTEND: +	case SCI_WORDRIGHTENDEXTEND:  	case SCI_HOME:  	case SCI_HOMEEXTEND:  	case SCI_LINEEND: @@ -6467,6 +6531,12 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {  	case SCI_DOCUMENTSTARTEXTEND:  	case SCI_DOCUMENTEND:  	case SCI_DOCUMENTENDEXTEND: + +	case SCI_STUTTEREDPAGEUP: +	case SCI_STUTTEREDPAGEUPEXTEND: +	case SCI_STUTTEREDPAGEDOWN: +	case SCI_STUTTEREDPAGEDOWNEXTEND: +  	case SCI_PAGEUP:  	case SCI_PAGEUPEXTEND:  	case SCI_PAGEDOWN: diff --git a/src/Editor.h b/src/Editor.h index 3a8d92a60..b8c32ab64 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -424,7 +424,7 @@ protected:	// ScintillaBase subclass needs access to much of Editor  	void NotifyStyleNeeded(Document *doc, void *userData, int endPos);  	void NotifyMacroRecord(unsigned int iMessage, uptr_t wParam, sptr_t lParam); -	void PageMove(int direction, selTypes sel=noSel); +	void PageMove(int direction, selTypes sel=noSel, bool stuttered = false);  	void ChangeCaseOfSelection(bool makeUpperCase);  	void LineTranspose();  	void LineDuplicate();  | 
