Skip to content

TextDocument#

Document object for text files. More...

import Script

Properties#

Name
int column
string currentLine
string currentWord
int line
int lineCount
LineEnding lineEnding
int position
string selectedText
int selectionEnd
int selectionStart
string text

Inherited properties: Document properties

Methods#

Name
columnAtPosition(int position)
copy()
Mark createMark(int pos = -1)
RangeMark createRangeMark()
RangeMark createRangeMark(int from, int to)
cut()
deleteEndOfLine()
deleteEndOfWord()
deleteLine(int line = -1)
deleteNextCharacter(int count = 1)
deletePreviousCharacter(int count = 1)
deleteRange(TextRange range)
deleteRegion(int from, int to)
deleteSelection()
deleteStartOfLine()
deleteStartOfWord()
bool find(string text, int options = TextDocument.NoFindFlags)
bool findRegexp(string regexp, int options = TextDocument.NoFindFlags)
gotoEndOfDocument()
gotoEndOfLine()
gotoEndOfWord()
gotoLine(int line, int column = 1)
gotoMark(Mark mark)
gotoNextChar(int count = 1)
gotoNextLine(int count = 1)
gotoNextWord(int count = 1)
gotoPreviousChar(int count = 1)
gotoPreviousLine(int count = 1)
gotoPreviousWord(int count = 1)
gotoStartOfDocument()
gotoStartOfLine()
gotoStartOfWord()
bool hasSelection()
indent(int count)
indentationAtPosition(int pos)
insert(string text)
insertAtLine(string text, int line = -1)
insertAtPosition(string text, int pos)
lineAtPosition(int position)
bool match(string regexp, int options = TextDocument.NoFindFlags)
paste()
positionAt(int line, int col)
redo(int count)
remove(int length)
removeIndent(int count)
replace(int length, string text)
replace(TextRange range, string text)
replace(int from, int to, string text)
bool replaceAll(string before, string after, int options = TextDocument.NoFindFlags)
bool replaceAllInRange(string before, string after, RangeMark range, int options = TextDocument.NoFindFlags)
bool replaceAllRegexp(string regexp, string after, int options = TextDocument.NoFindFlags)
bool replaceAllRegexpInRange(string regexp, string after, RangeMark range, int options = TextDocument.NoFindFlags)
bool replaceOne(string before, string after, int options = TextDocument.NoFindFlags)
selectAll()
selectEndOfLine()
selectEndOfWord()
selectNextChar(int count = 1)
selectNextLine(int count = 1)
selectNextWord(int count = 1)
selectPreviousChar(int count = 1)
selectPreviousLine(int count = 1)
selectPreviousWord(int count = 1)
selectRange(TextRange range)
selectRangeMark(RangeMark mark)
selectRegion(int from, int to)
selectStartOfLine(int count = 1)
selectStartOfWord()
selectTo(int pos)
selectToMark(Mark mark)
undo(int count)
unselect()

Inherited methods: Document methods

Property Documentation#

int column#

This read-only property holds the column of the cursor position. Be careful the column is 1-based, so the column before the first character is 1.

string currentLine#

This read-only property return the line under the current position.

string currentWord#

This read-only property return the word under the current position.

int line#

This read-only property holds the line of the cursor position. Be careful the line is 1-based, so the first line of the document is 1,

int lineCount#

This read-only property holds the number of lines in the document.

LineEnding lineEnding#

This property holds the line ending for the document. It can be one of those choices:

  • TextDocument.LFLineEnding: '\n' character
  • TextDocument.CRLFLineEnding: '\r\n' characters
  • TextDocument.NativeLineEnding: LF on Linux and Mac, CRLF on Windows

Native is the default for new documents.

int position#

This property holds the absolute position of the cursor inside the text document.

string selectedText#

This property holds the selected text of the document.

int selectionEnd#

This property holds the end of the selection or position if the cursor doesn't have a selection.

int selectionStart#

This property holds the start of the selection or position if the cursor doesn't have a selection.

string text#

This property holds the text of the document.

Method Documentation#

columnAtPosition(int position)#

Returns the column number for the given text cursor position. Or -1 if position is invalid

copy()#

Copies the selected text.

Mark createMark(int pos = -1)#

Creates a mark at the given position pos. If pos is -1, it will create a mark at the current position.

RangeMark createRangeMark()#

Creates a range mark from the current selection.

Note: if there is no selection, the range mark will span an empty range!

RangeMark createRangeMark(int from, int to)#

Creates a range mark from from to to.

cut()#

Cuts the selected text.

deleteEndOfLine()#

Deletes from the cursor position to the end of the line.

deleteEndOfWord()#

Deletes from the cursor position to the end of the word.

deleteLine(int line = -1)#

Remove a the line line. If line is -1, remove the current line. line is 1-based.

deleteNextCharacter(int count = 1)#

Deletes the next count characters.

deletePreviousCharacter(int count = 1)#

Deletes the previous count characters.

deleteRange(TextRange range)#

Deletes the range passed in parameter.

deleteRegion(int from, int to)#

Deletes the text between from and to positions.

deleteSelection()#

Deletes the current selection, does nothing if no text is selected.

deleteStartOfLine()#

Deletes from the cursor position to the start of the line.

deleteStartOfWord()#

Deletes from the cursor position to the start of the word.

bool find(string text, int options = TextDocument.NoFindFlags)#

Searches the string text in the editor. Options could be a combination of:

  • TextDocument.FindBackward: search backward
  • TextDocument.FindCaseSensitively: match case
  • TextDocument.FindWholeWords: match only complete words
  • TextDocument.FindRegexp: use a regexp, equivalent to calling findRegexp

Selects the match and returns true if a match is found.

bool findRegexp(string regexp, int options = TextDocument.NoFindFlags)#

Searches the string regexp in the editor using a regular expression. Options could be a combination of:

  • TextDocument.FindBackward: search backward
  • TextDocument.FindCaseSensitively: match case
  • TextDocument.FindWholeWords: match only complete words

Selects the match and returns true if a match is found.

gotoEndOfDocument()#

Goes to the document end.

gotoEndOfLine()#

Goes to the end of the line.

gotoEndOfWord()#

Goes to the end of the word under the cursor.

gotoLine(int line, int column = 1)#

Goes to the given line and column in the editor. Lines and columns are 1-based.

gotoMark(Mark mark)#

Goes to the given mark.

gotoNextChar(int count = 1)#

Goes to the next character, repeat the operation count times.

gotoNextLine(int count = 1)#

Goes to the next line, repeat the operation count times.

gotoNextWord(int count = 1)#

Goes to the next word, repeat the operation count times.

gotoPreviousChar(int count = 1)#

Goes to the previous character, repeat the operation count times.

gotoPreviousLine(int count = 1)#

Goes to the previous line, repeat the operation count times.

gotoPreviousWord(int count = 1)#

Goes to the previous word, repeat the operation count times.

gotoStartOfDocument()#

Goes to the document start.

gotoStartOfLine()#

Goes to the start of the line.

gotoStartOfWord()#

Goes to the start of the word under the cursor.

bool hasSelection()#

Returns true if the editor has a selection.

indent(int count)#

Indents the current line count times. If there's a selection, indent all lines in the selection.

indentationAtPosition(int pos)#

Returns the indentation at the given position.

insert(string text)#

Inserts the string text at the current position. If some text is selected it will be replaced.

insertAtLine(string text, int line = -1)#

Inserts the string text at line. If line is -1, insert the text at the current position. line is 1-based.

insertAtPosition(string text, int pos)#

Inserts the string text at pos.

lineAtPosition(int position)#

Returns the line number for the given text cursor position. Or -1 if position is invalid

bool match(string regexp, int options = TextDocument.NoFindFlags)#

Searches the string regexp in the editor using a regular expression. Options could be a combination of:

  • TextDocument.FindBackward: search backward
  • TextDocument.FindCaseSensitively: match case
  • TextDocument.FindWholeWords: match only complete words

Selects the match and returns the named group if a match is found.

paste()#

Pastes text in the clipboard.

positionAt(int line, int col)#

Returns the text cursor position for the given line number and column number. Or -1 if position was not found

redo(int count)#

Redo count times the last actions.

remove(int length)#

Remove length character from the current position.

removeIndent(int count)#

Indents the current line count times. If there's a selection, indent all lines in the selection.

replace(int length, string text)#

Replaces length characters from the current position with the string text.

replace(TextRange range, string text)#

Replaces the text in the range range with the string text.

replace(int from, int to, string text)#

Replaces the text from from to to with the string text.

bool replaceAll(string before, string after, int options = TextDocument.NoFindFlags)#

Replaces all occurrences of the string before with after. Options could be a combination of:

  • TextDocument.FindCaseSensitively: match case
  • TextDocument.FindWholeWords: match only complete words
  • TextDocument.FindRegexp: use a regexp, equivalent to calling findRegexp
  • TextDocument.PreserveCase: preserve case when replacing

If the option TextEditor.PreserveCase is used, it means:

  • All upper-case occurrences are replaced with the upper-case new text.
  • All lower-case occurrences are replaced with the lower-case new text.
  • Capitalized occurrences are replaced with the capitalized new text.
  • Other occurrences are replaced with the new text as entered. If an occurrence and the new text have the same prefix or suffix, then the case of the prefix and/or suffix are preserved, and the other rules are applied on the rest of the occurrence only.

Returns the number of changes done in the document.

bool replaceAllInRange(string before, string after, RangeMark range, int options = TextDocument.NoFindFlags)#

Replaces all occurrences of the string before with after in the given range. See the options from replaceAll.

Returns the number of changes done in the document.

bool replaceAllRegexp(string regexp, string after, int options = TextDocument.NoFindFlags)#

Replaces all occurrences of the matches for the regexp with after. See the options from replaceAll.

The captures coming from the regexp can be used in the replacement text, using \1..\n or $1..$n.

Returns the number of changes done in the document.

bool replaceAllRegexpInRange(string regexp, string after, RangeMark range, int options = TextDocument.NoFindFlags)#

Replaces all occurrences of the matches for the regexp with after in the given range. See the options from replaceAll.

The captures coming from the regexp can be used in the replacement text, using \1..\n or $1..$n.

Returns the number of changes done in the document.

bool replaceOne(string before, string after, int options = TextDocument.NoFindFlags)#

Replaces one occurrence of the string before with after. Options could be a combination of:

  • TextDocument.FindCaseSensitively: match case
  • TextDocument.FindWholeWords: match only complete words
  • TextDocument.FindRegexp: use a regexp, equivalent to calling findRegexp
  • TextDocument.PreserveCase: preserve case when replacing

If the option TextEditor.PreserveCase is used, it means:

  • All upper-case occurrences are replaced with the upper-case new text.
  • All lower-case occurrences are replaced with the lower-case new text.
  • Capitalized occurrences are replaced with the capitalized new text.
  • Other occurrences are replaced with the new text as entered. If an occurrence and the new text have the same prefix or suffix, then the case of the prefix and/or suffix are preserved, and the other rules are applied on the rest of the occurrence only.

Returns true if a change occurs in the document..

selectAll()#

Selects all the text.

selectEndOfLine()#

Selects the text from the current position to the end of the line.

selectEndOfWord()#

Selects the text from the current position to the end of the word.

selectNextChar(int count = 1)#

Selects the next character, repeat the operation count times.

selectNextLine(int count = 1)#

Selects the next line, repeat the operation count times.

selectNextWord(int count = 1)#

Selects the next word, repeat the operation count times.

selectPreviousChar(int count = 1)#

Selects the previous character, repeat the operation count times.

selectPreviousLine(int count = 1)#

Selects the previous line, repeat the operation count times.

selectPreviousWord(int count = 1)#

Selects the previous word, repeat the operation count times.

selectRange(TextRange range)#

Selects the range passed in parameter.

selectRangeMark(RangeMark mark)#

Selects the text defined by the range make mark.

selectRegion(int from, int to)#

Selects the text between from and to positions.

selectStartOfLine(int count = 1)#

Selects the text from the current position to the start of the line.

selectStartOfWord()#

Selects the text from the current position to the start of the word.

selectTo(int pos)#

Selects the text from the current position to pos.

selectToMark(Mark mark)#

Selects the text from the cursor position to the mark.

undo(int count)#

Undo count times the last actions.

unselect()#

Clears the current selection.