1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-28 11:35:35 +03:00

GH-666 WIP

This commit is contained in:
Tae Won Ha 2018-09-05 12:22:24 +02:00
parent 31ddc3e7be
commit 77e52c4162
2 changed files with 20 additions and 17 deletions

View File

@ -139,17 +139,16 @@ extension NvimView {
return false return false
} }
public func setMarkedText(_ aString: Any, selectedRange: NSRange, replacementRange: NSRange) { public func setMarkedText(
if self.markedText == nil { _ object: Any,
self.markedPosition = self.grid.position selectedRange: NSRange,
} replacementRange: NSRange
) {
stdoutLogger.debug("object: \(object), selectedRange: \(selectedRange), " +
"replacementRange: \(replacementRange)")
func setMarked(_ str: Any) { if self.markedText == nil {
switch str { self.markedPosition = self.ugrid.cursorPosition
case let string as String: self.markedText = string
case let attributedString as NSAttributedString: self.markedText = attributedString.string
default: self.markedText = String(describing: aString) // should not occur
}
} }
Single Single
@ -164,22 +163,20 @@ extension NvimView {
} }
.andThen( .andThen(
Single.create { single in Single.create { single in
switch aString { switch object {
case let string as String: case let string as String:
self.markedText = string self.markedText = string
case let attributedString as NSAttributedString: case let attributedString as NSAttributedString:
self.markedText = attributedString.string self.markedText = attributedString.string
default: default:
self.markedText = String(describing: aString) // should not occur self.markedText = String(describing: object) // should not occur
} }
// self.logger.debug("\(#function): \(self.markedText), \(selectedRange), \(replacementRange)")
single(.success(self.markedText!)) single(.success(self.markedText!))
return Disposables.create() return Disposables.create()
} }
) )
.flatMapCompletable { self.bridge.vimInputMarkedText($0) } .flatMapCompletable(self.bridge.vimInputMarkedText)
.trigger() .trigger()
self.keyDownDone = true self.keyDownDone = true
@ -210,7 +207,9 @@ extension NvimView {
} }
let result = NSRange( let result = NSRange(
location: self.grid.singleIndexFrom(self.grid.position), location: self.ugrid.flattenedCellIndex(
forPosition: self.ugrid.cursorPosition
),
length: 0 length: 0
) )
stdoutLogger.debug("Returning \(result)") stdoutLogger.debug("Returning \(result)")
@ -231,7 +230,7 @@ extension NvimView {
} }
public func hasMarkedText() -> Bool { public func hasMarkedText() -> Bool {
// self.logger.debug("\(#function)") stdoutLogger.debug("Marked text: \(String(describing: self.markedText))")
return self.markedText != nil return self.markedText != nil
} }

View File

@ -23,6 +23,10 @@ final class UGrid {
return !self.cells.isEmpty return !self.cells.isEmpty
} }
func flattenedCellIndex(forPosition position: Position) -> Int {
return position.row * self.size.width + position.column
}
func leftBoundaryOfWord(at position: Position) -> Int { func leftBoundaryOfWord(at position: Position) -> Int {
let column = position.column let column = position.column
let row = self.cells[position.row] let row = self.cells[position.row]