Skip to content Skip to sidebar Skip to footer

Multi-cursor Editing With Qscintilla

I'd like to create a little QScintilla widget supporting multi-cursor-editing like in SublimeText. As far as i know Scintilla already supports multiple cursors but I haven't seen a

Solution 1:

The multi-cursor feature is available in Scintilla, but QScintilla doesn't provide direct wrappers for this feature. However, you can "reimplement" your wrappers, since almost everything can be done with the SendScintilla method.

from PyQt5.Qsci import QsciScintilla
from PyQt5.QtWidgets import QApplication

app = QApplication([])

ed = QsciScintilla()

ed.setText('insert <-\nsome <-\ntext <-\n')
ed.show()

# typing should insertinall selections at the same time
ed.SendScintilla(ed.SCI_SETADDITIONALSELECTIONTYPING, 1)

# do multiple selections
offset= ed.positionFromLineIndex(0, 7) # line-index tooffset
ed.SendScintilla(ed.SCI_SETSELECTION, offset, offset)
# using the same offset twice selects no characters, hence a cursoroffset= ed.positionFromLineIndex(1, 5)
ed.SendScintilla(ed.SCI_ADDSELECTION, offset, offset)

offset= ed.positionFromLineIndex(2, 5)
ed.SendScintilla(ed.SCI_ADDSELECTION, offset, offset)

app.exec_()

You should wrap the SendScintilla calls in your own wrappers.

Keep in mind that the offsets are expressed in bytes and thus depend on the encoding of the text, which is more or less hidden by QScintilla's QStrings. On the other hand, the "line-index" are expressed in characters (codepoints if using unicode), and thus are more reliable.

Post a Comment for "Multi-cursor Editing With Qscintilla"