1

Notepad++ を使用して、テキスト ブロックを垂直方向に選択してコピーしています。テキストの最新ブロック (現在クリップボード バッファーにある) の貼り付けは正常に機能しますが、前の 2 番目と 3 番目のクリップボード バッファー (最初はブロックとしてコピーされたもの) に戻ると、これらの他のバッファーをブロックとしてではなく、最初の行の後に改行、2 行目の改行、など。

たとえば、次のブロックをブロック コピーするとします。

      test
      test
      test

最新のクリップボード バッファが次のように貼り付けられます

      test
      test
      test

カーソルが 4 つのスペースでインデントされていると仮定します。ただし、最新のクリップボード バッファーがクリップボード バッファー キューの 2 番目に移動されると、次のような貼り付けが行われます。

      test
test
test

以前のクリップボード バッファを保存するために ClipMate を使用しています。

notepad ++が最新のクリップボードテキストデータ(ブロックとしてコピー)をブロックペーストすることを知っているのに、最後から2番目のクリップボードバッファを知らないのはなぜですか?

クリップボード クリップのブロック状態を保存する方法はありますか?

4

2 に答える 2

1

Python Script Scintilla wrapper notepad++ プラグインを使用してソリューションを作成しました。

これをコピーして使います。 ショートカット Ctrl+c および Ctrl+INS へのマップ
として保存C:\Program Files\Notepad++\plugins\PythonScript\scripts\Samples\Copy.py

# $Revision: 1.2 $
# $Author: dot $
# $Date: 2012/03/23 20:59:46 $

from Npp import *
import string

# First we'll start an undo action, then Ctrl+z will undo the actions of the whole script
editor.beginUndoAction()

if editor.getSelText() != '':
    strClip = ""
    if editor.selectionIsRectangle():
        strClip = "<vertical>"+editor.getSelText()+"</vertical>"
    else:
        strClip = editor.getSelText()
    editor.copyText(strClip)

# End the undo action, so Ctrl+z will undo the above two actions
editor.endUndoAction()

これをカットに使います。 ショートカット Ctrl+x および Shift+DEL へのマップ
として保存C:\Program Files\Notepad++\plugins\PythonScript\scripts\Samples\Cut.py

# $Revision: 1.2 $
# $Author: dot $
# $Date: 2012/03/23 20:59:46 $

from Npp import *
import string

# First we'll start an undo action, then Ctrl+z will undo the actions of the whole script
editor.beginUndoAction()

if editor.getSelText() != '':
    strClip = ""
    if editor.selectionIsRectangle():
        strClip = "<vertical>"+editor.getSelText()+"</vertical>"
    else:
        strClip = editor.getSelText()
    editor.copyText(strClip)
    editor.clear()

# End the undo action, so Ctrl+z will undo the above two actions
editor.endUndoAction()

pyperclip.pyをダウンロードしてC:\Program Files\Notepad++\plugins\PythonScript\lib
、これを貼り付けに使用します。 ショートカット Ctrl+v および Shift+INS へのマップ
として保存C:\Program Files\Notepad++\plugins\PythonScript\scripts\Samples\Paste.py

# $Revision: 1.11 $
# $Author: dot $
# $Date: 2012/05/18 22:22:22 $

from Npp import *
import pyperclip
import string

#debug = True
debug = False

# First we'll start an undo action, then Ctrl-z will undo the actions of the whole script
editor.beginUndoAction()

# Get the clip
clip = pyperclip.getcb()

# Debug
if debug:
    bufferID = notepad.getCurrentBufferID()
    # Show console for debugging
    console.clear()
    console.show()

    console.write( "editor.getRectangularSelectionCaret()              = " + str(editor.getRectangularSelectionCaret() ) + "\n")
    console.write( "editor.getRectangularSelectionAnchor()             = " + str(editor.getRectangularSelectionAnchor()) + "\n")
    console.write( "editor.getSelectionStart()                         = " + str(editor.getSelectionStart()            ) + "\n")
    console.write( "editor.getSelectionEnd()                           = " + str(editor.getSelectionEnd()              ) + "\n")
    console.write( "editor.getCurrentPos()                             = " + str(editor.getCurrentPos()                ) + "\n")
    console.write( "editor.getAnchor()                                 = " + str(editor.getAnchor()                    ) + "\n")
    console.write( "editor.getRectangularSelectionAnchorVirtualSpace() = " + str(editor.getRectangularSelectionAnchorVirtualSpace()) + "\n")
    console.write( "editor.getRectangularSelectionCaretVirtualSpace()  = " + str(editor.getRectangularSelectionCaretVirtualSpace() ) + "\n")
    console.write( "editor.getSelectionNCaretVirtualSpace(0)           = " + str(editor.getSelectionNCaretVirtualSpace(0)          ) + "\n")
    console.write( "editor.getSelectionNAnchorVirtualSpace(0)          = " + str(editor.getSelectionNAnchorVirtualSpace(0)         ) + "\n")

if editor.getRectangularSelectionCaret()              == -1 and \
   editor.getRectangularSelectionAnchor()             == -1 and \
   editor.getSelectionStart()                         == 0  and \
   editor.getSelectionEnd()                           == 0  and \
   editor.getCurrentPos()                             == 0  and \
   editor.getAnchor()                                 == 0  and \
   editor.getRectangularSelectionAnchorVirtualSpace() == 0  and \
   editor.getRectangularSelectionCaretVirtualSpace()  == 0  and \
   editor.getSelectionNCaretVirtualSpace(0)           == 0  and \
   editor.getSelectionNAnchorVirtualSpace(0)          == 0:
    currentPos = editor.getCurrentPos()
    # Debug   
    if debug:   
        console.write( "state 0\n")
if editor.getRectangularSelectionCaret() != 0 and editor.getRectangularSelectionAnchor() != 0:
    if editor.getSelectionStart() == editor.getRectangularSelectionCaret() and \
       editor.getSelectionEnd()   == editor.getRectangularSelectionAnchor():
        # Debug
        if debug:
            console.write( "state 1\n" )
        currentPos = min(editor.getRectangularSelectionCaret(),editor.getRectangularSelectionAnchor())
    elif editor.getSelectionStart() < editor.getRectangularSelectionCaret():
        # Debug
        if debug:
            console.write( "state 2\n")
        currentPos = editor.getSelectionStart()
    elif editor.getSelectionStart() == editor.getRectangularSelectionCaret() and \
         editor.getSelectionEnd()   >  editor.getRectangularSelectionAnchor():
        currentPos = min(editor.getRectangularSelectionCaret(),editor.getRectangularSelectionAnchor())
        # Debug
        if debug:
            console.write( "state 3\n")
elif editor.getCurrentPos() != 0 and editor.getAnchor() != 0:
    # Debug
    if debug:
        console.write( "state 4\n")
    currentPos = min(editor.getCurrentPos(),editor.getAnchor())
elif editor.getSelectionStart() == editor.getRectangularSelectionCaret() and \
     editor.getSelectionEnd()   >  editor.getRectangularSelectionAnchor():
    # Debug
    if debug:
        console.write( "state 5\n")
    currentPos = min(editor.getRectangularSelectionCaret(),editor.getRectangularSelectionAnchor())
else:
    currentPos = editor.getCurrentPos()
    # Debug
    if debug:
        console.write( "state 6\n")

# Debug
if debug:
    console.write( "currentPos = " + str(currentPos) + "\n")

if editor.getRectangularSelectionAnchorVirtualSpace()   != editor.getRectangularSelectionCaretVirtualSpace() and \
   ( editor.getRectangularSelectionAnchorVirtualSpace() == editor.getSelectionNCaretVirtualSpace(0)          and \
     editor.getSelectionNCaretVirtualSpace(0)           == editor.getSelectionNAnchorVirtualSpace(0) ):
    prefix = editor.getRectangularSelectionCaretVirtualSpace()
    # Debug
    if debug:
        console.write( "state 7\n")
else:
    prefix = min(editor.getSelectionNCaretVirtualSpace(0),editor.getSelectionNAnchorVirtualSpace(0))
    # Debug
    if debug:
        console.write( "state 8\n")

# Debug
if debug:
    console.write( "prefix = " + str(prefix) + "\n")

prefixSpaces = "".ljust(prefix,' ') 
eolmode      = editor.getEOLMode()

# SC_EOL_CRLF (0), SC_EOL_CR (1), or SC_EOL_LF (2)
if eolmode == 0:
    eol = "\r\n"
    eolcnt = 2
elif eolmode == 1:
    eol = '\r'
    eolcnt = 1
elif eolmode == 2:
    eol = "\n"
    eolcnt = 1

if prefix > 0:
    if currentPos < editor.getCurrentPos():
        editor.insertText(editor.getLineEndPosition(editor.lineFromPosition(currentPos)),prefixSpaces)
        editor.gotoPos(editor.getLineEndPosition(editor.lineFromPosition(currentPos+prefix)))
        start = currentPos+prefix
        # Debug
        if debug:
            console.write( "state 9\n")
    else:
        editor.insertText(editor.getLineEndPosition(editor.lineFromPosition(editor.getCurrentPos())),prefixSpaces)
        editor.gotoPos(editor.getLineEndPosition(editor.lineFromPosition(editor.getCurrentPos())))
        start = editor.getCurrentPos()
        # Debug
        if debug:
            console.write( "state 10\n")
else:
    start = currentPos
    # Debug
    if debug:
        console.write( "state 11\n")

# Debug
if debug:
    console.write( "start = " + str(start) + "\n")

if clip != "":
    if editor.getSelectionStart() != editor.getSelectionEnd() and                                         \
       ( editor.getColumn(editor.getSelectionStart()) != editor.getColumn(editor.getSelectionEnd()) or    \
         ( editor.getColumn(editor.getSelectionStart()) == editor.getColumn(editor.getSelectionEnd()) and \
           editor.getColumn(editor.getSelectionStart()) == 0 ) ) and                                      \
       prefix == 0:
        editor.clear()
        # Debug
        if debug:
            console.write( "state 12\n")

    # We are dealing with a vertical paste
    if clip.startswith("<vertical>") and clip.endswith("</vertical>"):
        clip = clip[10:-11]

        startCol  = editor.getColumn(start)
        startRow  = editor.lineFromPosition(start)

        # Debug
        if debug:
            console.write( "startCol = " + str(startCol) + "\n")

        # Debug
        if debug:    
            console.write( "startRow = " + str(startRow) + "\n")

        # keepends = False
        clipSplit = clip.splitlines(False)

        clipSplitLen = len(clipSplit)

        for index,line in enumerate(clipSplit):
            if index == 0:
                localPrefixSpaces = ""
            elif index == (clipSplitLen-1):
                localPrefixSpaces = prefixSpaces
            else:
                localPrefixSpaces = prefixSpaces

            try:
                editorLine = editor.getLine(startRow+index).strip(eol)
                editorLineLen = len(editorLine)

                # Empty line
                if editorLineLen == 0:
                    editor.insertText(editor.positionFromLine(startRow+index),"".ljust(startCol,' '))
                    editor.insertText(editor.findColumn(startRow+index,startCol),line)
                else:
                    if editorLineLen < startCol:
                        editor.insertText(editor.getLineEndPosition(startRow+index),"".ljust(startCol-editorLineLen,' '))
                    editor.insertText(editor.findColumn(startRow+index,startCol),line)

            # End of file
            except IndexError:
                editor.documentEnd()
                editor.appendText(eol)
                editor.appendText("".ljust(startCol,' ') + line)

        editor.setCurrentPos(start)
        editor.setSelection(start,start)
    # We are dealing with a horizontal paste
    else:
        editor.insertText(start, clip)
        editor.setCurrentPos(start + len(clip))
        editor.setSelection(start + len(clip),start + len(clip))

# End the undo action, so Ctrl-z will undo the above two actions
editor.endUndoAction()

# Debug
if debug:
    notepad.activateBufferID(bufferID)

これは、VirtualSpaceOptions が 3 に設定されていることを前提としています。
ファイルC:\projects\misc\PythonScriptNppPlugin\startup.pyを次の
コードに変更し、notepad++ の起動ごとに実行されるようにします。

# $Revision: 1.2 $
# $Author: dot $
# $Date: 2012/03/23 20:59:46 $

# The lines up to and including sys.stderr should always come first
# Then any errors that occur later get reported to the console
# If you'd prefer to report errors to a file, you can do that instead here.
import sys
from Npp import *

# Set the stderr to the normal console as early as possible, in case of early errors
sys.stderr = console

# Define a class for writing to the console in red
class ConsoleError:
    def __init__(self):
        global console
        self._console = console;

    def write(self, text):
        self._console.writeError(text);

    def flush(self):
        pass

# Set the stderr to write errors in red
sys.stderr = ConsoleError()

# This imports the "normal" functions, including "help"
import site

# See docs
#   http://npppythonscript.sourceforge.net/docs/latest/intro.html
#   http://npppythonscript.sourceforge.net/docs/latest/scintilla.html
def set_word_chars(args):
    # Enable the virtual space options for both Scintilla views
    # For more information, see the Scintilla documentation on virtual space and the SCI_SETVIRTUALSPACEOPTIONS message.
    editor.setVirtualSpaceOptions(3)
    # Set the word characters
    editor.setWordChars('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$')

notepad.callback(set_word_chars, [NOTIFICATION.BUFFERACTIVATED])

# This sets the stdout to be the currently active document, so print "hello world", 
# will insert "hello world" at the current cursor position of the current document
sys.stdout = editor

editor.setVirtualSpaceOptions(3)
# Set the word characters
editor.setWordChars('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_$')
#console.show()
于 2012-03-23T18:14:17.283 に答える
1

Notepad++ は内部バッファから貼り付けており、クリップボードからデータを取得していないようです。MSDEVColumnSelect というプライベート データ形式がありますが、ClipMate に強制的にキャプチャさせようとすると、データが空になります。したがって、これは、アプリケーションがコピー/貼り付けを使用して煙と鏡のゲームをプレイしている場合のようであり、実際にはクリップボード機能ではありません。

于 2012-03-21T01:36:44.000 に答える