Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apple/TablePro/Core/Vim/VimEngine+Characters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,15 @@ extension VimEngine {
}
return max(position, limit)
}

// A character's class is its first scalar's, so a variation selector or mark never splits it.
func wordClass(at offset: Int, in buffer: VimTextBuffer) -> VimWordScanner.CharacterClass {
let base = characterStart(at: offset, in: buffer)
let trail = base + 1 < buffer.length ? buffer.character(at: base + 1) : nil
return VimWordScanner.characterClass(lead: buffer.character(at: base), trail: trail)
}

func isWordCharacter(at offset: Int, in buffer: VimTextBuffer) -> Bool {
wordClass(at: offset, in: buffer) == .word
}
}
16 changes: 12 additions & 4 deletions apple/TablePro/Core/Vim/VimEngine+InsertReplace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,33 @@ extension VimEngine {

func processCommandLine(_ char: Character, buffer commandBuffer: String) -> Bool {
switch char {
// Leaving the command line ends the command it is part of, an operator typed before it included.
case "\u{1B}":
cancelPendingCommand()
setMode(.normal)
return true
case "\r", "\n":
let prefix = commandBuffer.first
let body = String(commandBuffer.dropFirst())
setMode(.normal)
if prefix == "/" {
runSearch(pattern: body, forward: true)
} else if prefix == "?" {
runSearch(pattern: body, forward: false)
if prefix == "/" || prefix == "?" {
// A search after an operator is its motion, as `d/foo` deletes up to foo.
if pendingOperator != nil, let buffer {
let target = searchTarget(pattern: body, forward: prefix == "/", count: searchCount, in: buffer)
applyMotion(to: target, kind: .exclusive, in: buffer)
} else {
runSearch(pattern: body, forward: prefix == "/", count: searchCount)
}
} else {
onCommand?(body)
}
cancelPendingCommand()
return true
case "\u{7F}", "\u{08}":
if (commandBuffer as NSString).length > 1 {
setMode(.commandLine(buffer: String(commandBuffer.dropLast())))
} else {
cancelPendingCommand()
setMode(.normal)
}
return true
Expand Down
244 changes: 124 additions & 120 deletions apple/TablePro/Core/Vim/VimEngine+Motions.swift

Large diffs are not rendered by default.

Loading
Loading