Community
    • 登入

    Feature to switch clipboard text with highlited text.

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    4 貼文 2 Posters 2.5k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • wessam moustafaW
      wessam moustafa
      最後由 編輯

      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”.

      Scott SumnerS 1 條回覆 最後回覆 回覆 引用 0
      • Scott SumnerS
        Scott Sumner @wessam moustafa
        最後由 編輯

        @wessam-moustafa

        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)
        
        1 條回覆 最後回覆 回覆 引用 1
        • wessam moustafaW
          wessam moustafa
          最後由 編輯

          @Scott-Sumner

          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?

          Scott SumnerS 1 條回覆 最後回覆 回覆 引用 0
          • Scott SumnerS
            Scott Sumner @wessam moustafa
            最後由 編輯

            @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!

            1 條回覆 最後回覆 回覆 引用 0
            • 第一個貼文
              最後的貼文
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors