Improve loads of fancy things in relation to the mouse pointer
This commit is contained in:
@@ -16,7 +16,7 @@ struct CodeEditorConfiguration {
|
||||
/// Cheap identity of the marks; `makeMarks` runs only when it moves.
|
||||
var marksKey: String
|
||||
var makeMarks: () -> [Int: CodeLineMark]
|
||||
var opensDiffOnClick: Bool
|
||||
var offersShowDiff: Bool
|
||||
var knownSymbols: Set<String>
|
||||
var symbolsVersion: Int
|
||||
var flash: LineFlash?
|
||||
@@ -33,9 +33,8 @@ struct CodeEditorActions {
|
||||
var edited: (String) -> Void = { _ in }
|
||||
var cursorMoved: (_ line: Int, _ column: Int) -> Void = { _, _ in }
|
||||
var selectionChanged: (_ lines: ClosedRange<Int>?, _ code: String?) -> Void = { _, _ in }
|
||||
var markedLineClicked: (Int) -> Void = { _ in }
|
||||
/// Reference, selected code, and the anchor in top-left window coordinates.
|
||||
var contextMenu: (AgentReference, String?, CGPoint) -> Void = { _, _, _ in }
|
||||
/// Reference, selected code, the line that offers Show diff, and the anchor in top-left window coordinates.
|
||||
var contextMenu: (AgentReference, String?, Int?, CGPoint) -> Void = { _, _, _, _ in }
|
||||
var symbolClicked: (String) -> Void = { _ in }
|
||||
/// ⌘→ with a selection; returns false when there was nothing to pass.
|
||||
var passOnSelection: (CGPoint) -> Bool = { _ in false }
|
||||
@@ -436,12 +435,17 @@ final class CodeEditorController: NSObject, NSTextViewDelegate, NSLayoutManagerD
|
||||
return doc.lineIndex.line(containing: characterIndex(atWindowPoint: point))
|
||||
}
|
||||
|
||||
/// A plain click on a marked line in Actual opens the Diff there.
|
||||
func plainClick(atWindowPoint point: NSPoint) {
|
||||
guard configuration?.opensDiffOnClick == true,
|
||||
let line = line(atWindowPoint: point), marks[line] != nil else { return }
|
||||
let action = actions.markedLineClicked
|
||||
DispatchQueue.main.async { action(line) }
|
||||
/// The marked line under the point when the file offers Show diff. The whole row counts,
|
||||
/// so a blank line and the space after the last glyph hit too.
|
||||
func showDiffLine(atWindowPoint point: NSPoint) -> Int? {
|
||||
guard configuration?.offersShowDiff == true else { return nil }
|
||||
let local = textView.convert(point, from: nil)
|
||||
var hit: Int?
|
||||
forEachRow(in: NSRect(x: 0, y: local.y, width: max(1, textView.bounds.width), height: 1)) { row in
|
||||
if hit == nil, row.rect.minY <= local.y, local.y < row.rect.maxY { hit = row.line }
|
||||
}
|
||||
guard let hit, marks[hit] != nil else { return nil }
|
||||
return hit
|
||||
}
|
||||
|
||||
/// ⌘-click: follows a class name the project declares.
|
||||
@@ -472,7 +476,7 @@ final class CodeEditorController: NSObject, NSTextViewDelegate, NSLayoutManagerD
|
||||
let lines = selection.length > 0 ? EditorReference.lines(of: selection, in: doc.lineIndex) : nil
|
||||
let code = selection.length > 0 ? (doc.storage.string as NSString).substring(with: clamped(selection, in: doc)) : nil
|
||||
let reference = EditorReference.make(path: configuration.path, selectedLines: lines, clickedLine: clicked)
|
||||
actions.contextMenu(reference, code, topLeft(event.locationInWindow))
|
||||
actions.contextMenu(reference, code, showDiffLine(atWindowPoint: event.locationInWindow), topLeft(event.locationInWindow))
|
||||
}
|
||||
|
||||
func passOnSelection() -> Bool {
|
||||
|
||||
Reference in New Issue
Block a user