mirror of
https://github.com/TermoraDev/termora.git
synced 2026-01-16 02:12:58 +08:00
fix: max row selection
This commit is contained in:
@@ -14,6 +14,11 @@ open class DocumentImpl(private val terminal: Terminal) : Document {
|
||||
|
||||
companion object {
|
||||
private val log = LoggerFactory.getLogger(DocumentImpl::class.java)
|
||||
|
||||
/**
|
||||
* 超出的行数
|
||||
*/
|
||||
val OverflowLines = DataKey(Int::class)
|
||||
}
|
||||
|
||||
init {
|
||||
|
||||
@@ -4,6 +4,20 @@ package app.termora.terminal
|
||||
open class MarkupModelImpl(private val terminal: Terminal) : MarkupModel {
|
||||
private val highlighters = mutableMapOf<Int, MutableList<Highlighter>>()
|
||||
|
||||
init {
|
||||
terminal.getTerminalModel().addDataListener(object : DataListener {
|
||||
override fun onChanged(key: DataKey<*>, data: Any) {
|
||||
if (key != DocumentImpl.OverflowLines) return
|
||||
if (highlighters.isEmpty()) return
|
||||
val row = data as Int
|
||||
// 因为第 N 行被删除了,所以这里要删除这一行的荧光笔
|
||||
for (i in 0 until row) {
|
||||
terminal.getMarkupModel().removeAllHighlightersInLine(0)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun addHighlighter(highlighter: Highlighter) {
|
||||
val range = highlighter.getHighlighterRange()
|
||||
highlighters.getOrPut(range.start.y) { mutableListOf() }.addLast(highlighter)
|
||||
|
||||
@@ -32,6 +32,34 @@ open class SelectionModelImpl(private val terminal: Terminal) : SelectionModel {
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
terminal.getTerminalModel().addDataListener(object : DataListener {
|
||||
private val cols get() = terminal.getTerminalModel().getCols()
|
||||
override fun onChanged(key: DataKey<*>, data: Any) {
|
||||
if (key != DocumentImpl.OverflowLines) return
|
||||
if (!hasSelection() || isSelectAll()) return
|
||||
val row = data as Int
|
||||
|
||||
val startPosition = startPosition.copy(y = max(startPosition.y - row, 1))
|
||||
val endPosition = endPosition.copy(y = endPosition.y - row)
|
||||
if (endPosition.y < 1 || endPosition.y < startPosition.y) {
|
||||
clearSelection()
|
||||
return
|
||||
}
|
||||
|
||||
// 设置新的选择区域
|
||||
setSelection(startPosition, endPosition)
|
||||
|
||||
}
|
||||
|
||||
private fun isSelectAll(): Boolean {
|
||||
return hasSelection() &&
|
||||
startPosition.y == 1 && startPosition.x == 1 &&
|
||||
endPosition.y == document.getLineCount() && endPosition.x == cols
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun getSelectedText(): String {
|
||||
val sb = StringBuilder()
|
||||
|
||||
|
||||
@@ -61,8 +61,8 @@ class TerminalLineBuffer(
|
||||
if (!resizing) {
|
||||
while (size > terminalModel.getMaxRows()) {
|
||||
removeFirst()
|
||||
// 因为第一行被删除了,所以这里要删除这一行的荧光笔
|
||||
terminal.getMarkupModel().removeAllHighlightersInLine(0)
|
||||
// 超出的行数,前 N 行已经被清理
|
||||
terminal.getTerminalModel().setData(DocumentImpl.OverflowLines, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user