Repository navigation
Conversation
When smart insert/delete is enabled, replacing a part of a word joined
by an additional word separator, such as the "111" in ".111", by pasting
a word inserted an unwanted space after the separator (". 222").
NSTextView adds a space after some punctuation for natural language, but
CotEditor treats ".", ",", and ":" as word separators so that a part of
a token like "foo.bar", "1,000", or "12:30" can be selected by
double-clicking. Now, smart insert no longer adds spaces next to these
separators when replacing a selection, while the default behavior is
kept when inserting at an insertion point.
Member
|
@ryochin Thank you for the detailed report and the suggestion for the fix! I've committed a more compact version of the fix in 1b408a5, so let me close this PR. The main differences are:
I also credited you in the changelog. Thanks again for your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When "Smart copy/paste" is enabled, replacing a part of a word that is joined by an additional word separator (
.,,, or:) with a pasted word inserts an unwanted space after the separator.Steps to reproduce
.111on the first line and222on the second line.222to select it and copy it.NSTextViewadds only when copying a word-level selection with Smart copy/paste enabled.111to select it and paste..222. 222The same happens with
1,000and12:30, but not with/.Cause
NSTextView.smartInsert(beforeStringFor:replacing:)returns a space when the preceding character is punctuation such as.,,,;,:,), or=. This is intended for natural language (e.g., pasting a word afterHello.results inHello. world), and plainNSTextViewbehaves the same way.However, CotEditor treats
.,,, and:as additional word separators (EditorTextView.additionalWordSeparators) so that a part of a token likefoo.bar,1,000, or12:30can be selected by double-clicking. Replacing such a part splits the token with the space.Changes
smartInsert(beforeStringFor:replacing:)andsmartInsert(afterStringFor:replacing:)inEditorTextViewto suppress the space when the adjacent character is an additional word separator and a non-empty range is being replaced.Hello.+worldstill results inHello. world.isAdditionalWordSeparator(at:)soadditionalWordSeparatorscan stay private.=and), is left to AppKit.Tests
Added to
CursorMovementTests:smartInsertNextToSeparator(string:range:): replacing a part of.111,1,000,12:30, andfoo.baradds no spaces.smartInsertAtInsertionPointAfterSeparator(): inserting at an insertion point after.still adds a space.smartPasteNextToSeparator(): an actual smart paste viareadSelection(from:type:)turns.111into.222.I confirmed that the first and third tests fail without the fix and that all tests in
CursorMovementTestspass with it. I also checked the fix manually in a local build.