From ed404335a35853d9250c703a3f28acde63b9b20d Mon Sep 17 00:00:00 2001 From: Neil Hodgson Date: Wed, 26 Mar 2014 11:23:55 +1100 Subject: Refactor range deletion into a method on ScintillaView. For removeMarkedText, use range deletion instead of setting the selection and inserting an empty string as this has fewer side effects and should avoid crashes when an autocompletion list is active. --- cocoa/ScintillaView.h | 2 ++ cocoa/ScintillaView.mm | 36 +++++++++++++++++------------------- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'cocoa') diff --git a/cocoa/ScintillaView.h b/cocoa/ScintillaView.h index 51d60e9d5..b9b36201f 100644 --- a/cocoa/ScintillaView.h +++ b/cocoa/ScintillaView.h @@ -146,6 +146,8 @@ extern NSString *const SCIUpdateUINotification; - (NSString*) selectedString; +- (void) deleteRange: (NSRange) range; + - (void)setFontName: (NSString*) font size: (int) size bold: (BOOL) bold diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index 2db8fae12..97bc0edfe 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -383,13 +383,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) // Its replacing a non-existent position so do nothing. return; - if (replacementRange.length > 0) - { - [ScintillaView directCall: mOwner - message: SCI_DELETERANGE - wParam: replacementRange.location - lParam: replacementRange.length]; - } + [mOwner deleteRange: replacementRange]; NSString* newText = @""; if ([aString isKindOfClass:[NSString class]]) @@ -459,13 +453,7 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) mOwner.backend->SelectOnlyMainSelection(); } - if (replacementRange.length > 0) - { - [ScintillaView directCall: mOwner - message: SCI_DELETERANGE - wParam: replacementRange.location - lParam: replacementRange.length]; - } + [mOwner deleteRange: replacementRange]; // Note: Scintilla internally works almost always with bytes instead chars, so we need to take // this into account when determining selection ranges and such. @@ -532,11 +520,8 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) if (mMarkedTextRange.length > 0) { // We have already marked text. Replace that. - [mOwner setGeneralProperty: SCI_SETSELECTIONSTART - value: mMarkedTextRange.location]; - [mOwner setGeneralProperty: SCI_SETSELECTIONEND - value: mMarkedTextRange.location + mMarkedTextRange.length]; - mOwner.backend->InsertText(@""); + [mOwner deleteRange: mMarkedTextRange]; + mMarkedTextRange = NSMakeRange(NSNotFound, 0); // Reenable undo action collection, after we are done with text composition. @@ -1253,6 +1238,19 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) //-------------------------------------------------------------------------------------------------- +/** + * Delete a range from the document. + */ +- (void) deleteRange: (NSRange) aRange +{ + if (aRange.length > 0) + { + [self message: SCI_DELETERANGE wParam: aRange.location lParam: aRange.length]; + } +} + +//-------------------------------------------------------------------------------------------------- + /** * Getter for the current text in raw form (no formatting information included). * If there is no text available an empty string is returned. -- cgit v1.2.3