def selectedText(): """ Returns the currenty selected text or an empty string. """ if kate.view().selection.exists: return kate.view().selection.text else: return ''
def replaceSelectionWith(text, keepSelection = False): """ Replaces the selection in the current view with text, and reselects the newly inserted text if keepSelection == True """ d, v, s = kate.document(), kate.view(), kate.view().selection if s.exists: line, col = s.region[0] else: line, col = v.cursor.position lines = text.split('\n') endline, endcol = line + len(lines) - 1, len(lines[-1]) if len(lines) < 2: endcol += col d.editingSequence.begin() if s.exists: s.removeSelectedText() v.insertText(text) d.editingSequence.end() if keepSelection: s.region = ((line, col), (endline, endcol))
def setPos(linepos, col = None): """Set the cursor position to line, col or (line, col).""" if col is None: kate.view().cursor.position = linepos else: kate.view().cursor.position = (linepos, col)
def pos(): """The cursor position.""" return kate.view().cursor.position
def currentLine(): """The text on the current line.""" return kate.view().currentLine
def hasSelection(): """True if there is a selection""" return kate.view().selection.exists
def insertText(text): kate.view().insertText(text)