Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Toggle CaSe

2011-06-02
2013-01-25
  • Dragos Toader
    Dragos Toader
    2011-06-02

    from Npp import *
    import string
    if editor.selectionIsRectangle():
        start    = editor.getRectangularSelectionAnchor()
        end      = editor.getRectangularSelectionCaret()
        startCol = editor.getColumn(start)
        endCol   = editor.getColumn(end)
        startRow = editor.lineFromPosition(start)
        endRow   = editor.lineFromPosition(end)
        
        if startCol > endCol:
            temp     = startCol
            startCol = endCol
            endCol   = temp
        if startRow > endRow:
            temp     = startRow
            startRow = endRow
            endRow   = temp
        endRow += 1
        
        minPos = 0
        maxPos = 0
        for line in range(startRow,endRow):
            charstr = ""
            for i,column in enumerate(range(startCol,endCol)):
                pos = editor.findColumn(line, column)
                if i == 0 :
                    minPos = pos
                charstr += chr(editor.getCharAt(pos))
            maxPos = pos
            
            editor.setSel(minPos,maxPos+1)
            editor.replaceSel(charstr.swapcase())
            
        editor.setRectangularSelectionAnchor(start)
        editor.setRectangularSelectionCaret(end)
    else:
        if editor.getSelText() == '':
            editor.setSel(editor.getCurrentPos(),editor.getCurrentPos()+1)
        editor.replaceSel(editor.getSelText().swapcase())
        editor.setSel(editor.getCurrentPos(),editor.getCurrentPos())
    
     

  • Anonymous
    2011-06-03

    I fixed a bug that appears with carriage returns in a rectangular block of text.

    from Npp import *
    import string
    if editor.selectionIsRectangle():
        start    = editor.getRectangularSelectionAnchor()
        end      = editor.getRectangularSelectionCaret()
        if start > end:
            temp  = start
            start = end
            end   = temp
        
        startCol = editor.getColumn(start)
        endCol   = 0
        for i in range(start,end):
            newEndCol = editor.getColumn(i)
            if endCol < newEndCol:
                endCol = newEndCol
        endCol  += 1
        startRow = editor.lineFromPosition(start)
        endRow   = editor.lineFromPosition(end  ) + 1
        """
        console.write(
           "\n\n----------------------" +
           "\nstart    "+str(start   )  +
           "\nend      "+str(end     )  +
           "\nstartCol "+str(startCol)  +
           "\nendCol   "+str(endCol  )  +
           "\nstartRow "+str(startRow)  +
           "\nendRow   "+str(endRow  )  )
        """
        
        for line in range(startRow,endRow):
            minPos  = 0
            maxPos  = 0
            charstr = ""
            empty   = False
            for i,column in enumerate(range(startCol,endCol)):
                pos   = editor.findColumn(line, column)
                char  = chr(editor.getCharAt(pos))
                """
                console.write(
                   "\n\n----------------------" +
                   "\nline     "+str(line    )  +
                   "\ncolumn   "+str(column  )  +
                   "\npos      "+str(pos     )  +
                   "\nchar    '"+char           +"'" )
                """
                
                if i == 0:
                    minPos = pos
                    maxPos = pos
                    if not (char == '' or ord(char) == 13):
                        empty  = False
                    else:
                        empty = True
                else:
                    if not (char == '' or ord(char) == 13):
                        maxPos = pos
                        empty  = False
                    else:
                        empty  = True
                if not empty:
                   charstr += char
                """
                console.write(
                   "\n\n    -------------------" +
                   "\n    Line      "+str(line   )  +
                   "\n    Column    "+str(column )  +
                   "\n    Pos       "+str(pos    )  +
                   "\n    Char     '"+char          + "'" +
                   "\n    ord(char) "+str(ord(char))+
                   "\n    Emtpy     "+str(empty  )  +
                   "\n    minPos    "+str(minPos )  +
                   "\n    maxPos    "+str(maxPos )  +
                   "\n    charstr  '"+charstr       + "'" )
                """
            if not (minPos == 0 and maxPos == 0):
                editor.setSel(minPos,maxPos+1)
                editor.replaceSel(charstr.swapcase())
            
        editor.setRectangularSelectionAnchor(start)
        editor.setRectangularSelectionCaret(end)
    else:
        if editor.getSelText() == '':
            editor.setSel(editor.getCurrentPos(),editor.getCurrentPos()+1)
        editor.replaceSel(editor.getSelText().swapcase())
        editor.setSel(editor.getCurrentPos(),editor.getCurrentPos())