我想创建一个像SublimeText一样支持多光标编辑的小QScintilla小部件。据我所知,Scintilla已经支持多个游标,但我还没有看到任何例子。
那么,有没有人可以贴出一个小例子,展示一下QScintilla中多个游标的基础知识?
发布于 2016-08-11 06:44:33
多光标功能在Scintilla中可用,但QScintilla没有为该功能提供直接包装器。但是,您可以“重新实现”包装器,因为几乎所有事情都可以使用SendScintilla方法完成。
from PyQt5.Qsci import QsciScintilla
from PyQt5.QtWidgets import QApplication
app = QApplication([])
ed = QsciScintilla()
ed.setText('insert <-\nsome <-\ntext <-\n')
ed.show()
# typing should insert in all selections at the same time
ed.SendScintilla(ed.SCI_SETADDITIONALSELECTIONTYPING, 1)
# do multiple selections
offset = ed.positionFromLineIndex(0, 7) # line-index to offset
ed.SendScintilla(ed.SCI_SETSELECTION, offset, offset)
# using the same offset twice selects no characters, hence a cursor
offset = 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_()您应该将SendScintilla调用包装在您自己的包装器中。
请记住,offset是以字节表示的,因此依赖于文本的编码,这或多或少被QScintilla的QStrings所隐藏。另一方面,“行索引”是用字符表示的(如果使用unicode,则为代码点),因此更可靠。
https://stackoverflow.com/questions/38850277
复制相似问题