56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// Selection is owned by the session's anchor and cursor. Compare ranges in the
|
|
// current document without retaining text or inventing a native object identity.
|
|
func (session *ocrSession) selection_change_locked(oldStart, oldEnd int) string {
|
|
start, end := session.selection_locked()
|
|
var changes []string
|
|
fragment := func(from, to int, selected bool) {
|
|
if from < 0 || to <= from {
|
|
return
|
|
}
|
|
message := "unselected"
|
|
if selected {
|
|
message = "selected"
|
|
}
|
|
if to-from <= lineSelectionFragmentLimit {
|
|
value, _ := session.cursor.Slice(from, to)
|
|
value = strings.Join(strings.Fields(value), " ")
|
|
if value != "" {
|
|
if selected {
|
|
message = fmt.Sprintf("%s selected", value)
|
|
} else {
|
|
message = fmt.Sprintf("%s unselected", value)
|
|
}
|
|
}
|
|
}
|
|
changes = append(changes, message)
|
|
}
|
|
if oldEnd > oldStart {
|
|
if end <= start {
|
|
fragment(oldStart, oldEnd, false)
|
|
} else {
|
|
fragment(oldStart, min(oldEnd, start), false)
|
|
fragment(max(oldStart, end), oldEnd, false)
|
|
}
|
|
}
|
|
if end > start {
|
|
if oldEnd <= oldStart {
|
|
fragment(start, end, true)
|
|
} else {
|
|
fragment(start, min(end, oldStart), true)
|
|
fragment(max(start, oldEnd), end, true)
|
|
}
|
|
}
|
|
return strings.Join(changes, ", ")
|
|
}
|