Paste as plain text functionality#37
Conversation
e6b946b to
9606cb2
Compare
|
it seems that instead of modifying SetRangeToText() for this purpose, the KeyDown event can just be routed case Key.V: if (e.KeyModifiers.HasFlag(KeyModifiers.Shift)) something like that? |
|
What about refactoring all shortcuts like this: |
9606cb2 to
2b066a9
Compare
|
i pushed the refactoring changes: https://github.com/cuikp/AvRichTextBox/pull/37/changes#diff-48bfca98ca08e70676a2f09bdcc283fefb292ebd6818047f848d1b26390ac739 |
|
The changes to Actually I'm not sure there's a need for separate extra method of: Regarding the refactoring of key handling, is there some advantage to those changes? (i.e. I also think RichTextBox will need a switch to enable/disable this action on Ctrl-Shift-V, because developers of the control might not want it or will have other uses for Ctrl-Shift-V. But I'll add that later after merging. Or maybe a switch to enable/disable all hotkeys or just copy/paste related hotkeys, idk. |
|
I added the extra method PasteFromClipboardAsPlainText just so that it is easier to understand. With PasteFromClipboard(true) you have to first look to see what 'true' means. Regarding the shortcut-refactoring: Using this approach avoids the issue which was there earlier, where the combination isn't strict enough (for example CTRL+SHIFT+C also copies text). It makes such cases impossible, because you have to explicitly define which modified-keys are necessary. |
|
Re: shortcut refactoring - makes sense, ok. Just have to get used to looking at that syntax. Re: interpreting PasteFromClipboard(true), it could be specified as: |
|
PasteFromClipboard(plainTextOnly: true) is also ok. I will change it. |
|
Merged. Looks good, thx. Later I'm going to add a StyledProperty to RTB to enabled/disable just the editing shortcuts (enabled by default), since some users may not want them at all. |
This PR adds the functionality to paste as plain text with shortcut CTRL+SHIFT+V or using the context menu.
If the text where the clipboard-data is inserted at has already formatting, than this formatting will not be applied to the inserted text. This is how for example LibreOffice Writer works, but I'm open to change this.Update: That's actually not correct. Existing formatting is applied in LibreOffice Writer.
Should the changes in commit b7ea0e1 be undone?I reverted the changes, so it like most users probably expect it to work (use formatting that the current text in the control has). A way to clear formatting could be added in addition.
The addUndo variable and if-clause has been removed, because addUndo is always true. This change can be reverted, if there is a reason to keep it, of course.