Feature to switch clipboard text with highlited text.
-
Do we have a feature where we can replace the clipboard text with the current highlighted text?
Ex:
Clipboard has text “XXX” and we have the text “YYY” highlighted in the text editing area. Do we have an option/feature where we can switch them so that clipboard get the “YYY” and the highlighted “YYY” get replaced by “XXX”. -
This is not a native Notepad++ function, nor is it provided by any plug-in that I’m aware of. However, a few lines of Pythonscript code can do it if you’re willing to install that plug-in…for example:
def simple_clipboard_set_text(text_to_put_in_cb): doc_length = editor.getTextLength() curr_pos = editor.getCurrentPos() editor.beginUndoAction() editor.insertText(curr_pos, text_to_put_in_cb) editor.setSel(curr_pos, curr_pos + editor.getTextLength() - doc_length) editor.endUndoAction() editor.copy() # put text in clipboard editor.undo() if not editor.getSelectionEmpty(): if editor.getSelections() == 1: if editor.getSelectionMode() == SELECTIONMODE.STREAM: orig_selected_text = editor.getSelText() editor.paste() # overwrite existing selection simple_clipboard_set_text(orig_selected_text) -
Thx a lot. That really helped :)
Just wondering whey didn’t you use “Editor.copyText(text) → int” instead of the “simple_clipboard_set_text” function?
-
@wessam-moustafa said:
Just wondering whey didn’t you use “Editor.copyText(text) → int”
No good reason for not using that function in this. I think I copied the more complex code from a script I had which was doing something a bit more complicated, and totally unnecessary for swapping clipboard and selected text. Thanks for pointing out the simplification!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login