From 170447f5316e9297a91de3a86fb46c476aa22771 Mon Sep 17 00:00:00 2001 From: Tae Won Ha Date: Sun, 30 Sep 2018 17:53:35 +0200 Subject: [PATCH] =?UTF-8?q?GH-666=20Make=20simple=20composed=20input,=20eg?= =?UTF-8?q?=20`=C3=BC`,=20work.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NvimView/NvimView/Logger.swift | 5 -- NvimView/NvimView/NvimView+Api.swift | 2 +- NvimView/NvimView/NvimView+Key.swift | 43 ++++++++--------- NvimView/NvimView/NvimView+UiBridge.swift | 56 +++++++++++------------ NvimView/NvimView/NvimView.swift | 8 +++- NvimView/NvimView/Runs.swift | 2 +- 6 files changed, 57 insertions(+), 59 deletions(-) diff --git a/NvimView/NvimView/Logger.swift b/NvimView/NvimView/Logger.swift index fe30b572..b0aecf7e 100644 --- a/NvimView/NvimView/Logger.swift +++ b/NvimView/NvimView/Logger.swift @@ -9,11 +9,6 @@ let stdoutLogger = LogContext.stdoutLogger(as: "NvimView") let logger = LogContext.fileLogger( as: "NvimView", with: URL(fileURLWithPath: "/tmp/nvv.log") ) -let bridgeLogger = LogContext.fileLogger( - as: "NvimView-Bridge", - with: URL(fileURLWithPath: "/tmp/nvv-bridge.log"), - shouldLogDebug: nil -) class LogContext { diff --git a/NvimView/NvimView/NvimView+Api.swift b/NvimView/NvimView/NvimView+Api.swift index c91d13a8..ab913c0d 100644 --- a/NvimView/NvimView/NvimView+Api.swift +++ b/NvimView/NvimView/NvimView+Api.swift @@ -150,7 +150,7 @@ extension NvimView { } public func quitNeoVimWithoutSaving() -> Completable { - bridgeLogger.mark() + self.bridgeLogger.mark() return self.api .command(command: "qa!") .subscribeOn(self.scheduler) diff --git a/NvimView/NvimView/NvimView+Key.swift b/NvimView/NvimView/NvimView+Key.swift index 1b6d9f9f..4a58075d 100644 --- a/NvimView/NvimView/NvimView+Key.swift +++ b/NvimView/NvimView/NvimView+Key.swift @@ -15,7 +15,7 @@ extension NvimView { let modifierFlags = event.modifierFlags let isMeta = (self.isLeftOptionMeta && modifierFlags.contains(.leftOption)) - || (self.isRightOptionMeta && modifierFlags.contains(.rightOption)) + || (self.isRightOptionMeta && modifierFlags.contains(.rightOption)) if !isMeta { let cocoaHandledEvent = NSTextInputContext.current?.handleEvent(event) ?? false @@ -40,44 +40,41 @@ extension NvimView { let namedChars = KeyUtils.namedKey(from: charsIgnoringModifiers) let finalInput = isWrapNeeded ? self.wrapNamedKeys(flags + namedChars) : self.vimPlainString(chars) - self.bridge - .vimInput(finalInput) - .trigger() - + try? self.bridge.vimInput(finalInput).wait() self.keyDownDone = true } public func insertText(_ object: Any, replacementRange: NSRange) { stdoutLogger.debug("\(object) with \(replacementRange)") - let deleteMarkedText: Completable - if let marked = self.markedText { - let delSeq = Array(repeating: "", count: marked.count).joined() - deleteMarkedText = Single - .just(delSeq) - .flatMapCompletable { self.bridge.vimInput($0) } - } else { - deleteMarkedText = Completable.empty() - } - + let text: String switch object { case let string as String: - self.bridge - .vimInput(self.vimPlainString(string)) - .trigger() + text = string case let attributedString as NSAttributedString: - self.bridge - .vimInput(self.vimPlainString(attributedString.string)) - .trigger() + text = attributedString.string default: - break; + return } - // unmarkText() + try? Single + .just((self.markedText, text)) + .flatMap { element -> Single in + if let marked = element.0 { + return self.bridge + .deleteCharacters(marked.count) + .andThen(Single.just(element.1)) + } else { + return Single.just(element.1) + } + } + .flatMapCompletable { self.bridge.vimInput(self.vimPlainString($0)) } + .wait() + self.lastMarkedText = self.markedText self.markedText = nil self.markedPosition = .null diff --git a/NvimView/NvimView/NvimView+UiBridge.swift b/NvimView/NvimView/NvimView+UiBridge.swift index 888bdcf5..e61cc671 100644 --- a/NvimView/NvimView/NvimView+UiBridge.swift +++ b/NvimView/NvimView/NvimView+UiBridge.swift @@ -17,7 +17,7 @@ extension NvimView { return } - bridgeLogger.debug("\(array[0]) x \(array[1])") + self.bridgeLogger.debug("\(array[0]) x \(array[1])") gui.async { self.ugrid.resize(Size(width: array[0], height: array[1])) self.markForRenderWholeView() @@ -25,7 +25,7 @@ extension NvimView { } final func clear() { - bridgeLogger.mark() + self.bridgeLogger.mark() gui.async { self.ugrid.clear() @@ -44,7 +44,7 @@ extension NvimView { return } - bridgeLogger.debug(self.name(ofCursorMode: mode)) + self.bridgeLogger.debug(self.name(ofCursorMode: mode)) gui.async { self.mode = mode self.markForRender( @@ -54,7 +54,7 @@ extension NvimView { } final func unmark(_ value: MessagePackValue) { -// bridgeLogger.debug("\(row):\(column)") +// self.bridgeLogger.debug("\(row):\(column)") // // gui.async { // let position = Position(row: row, column: column) @@ -65,7 +65,7 @@ extension NvimView { } final func flush(_ renderData: [MessagePackValue]) { - bridgeLogger.debug("# of render data: \(renderData.count)") + self.bridgeLogger.debug("# of render data: \(renderData.count)") gui.async { renderData.forEach { value in @@ -90,7 +90,7 @@ extension NvimView { case .scroll: let values = innerArray.compactMap { $0.intValue } guard values.count == 6 else { - bridgeLogger.error("Scroll msg does not have 6 Int's!") + self.bridgeLogger.error("Scroll msg does not have 6 Int's!") return } @@ -111,12 +111,12 @@ extension NvimView { final func setTitle(with value: MessagePackValue) { guard let title = value.stringValue else { return } - bridgeLogger.debug(title) + self.bridgeLogger.debug(title) self.eventsSubject.onNext(.setTitle(title)) } final func stop() { - bridgeLogger.hr() + self.bridgeLogger.hr() try? self.api .stop() .andThen(self.bridge.quit()) @@ -141,7 +141,7 @@ extension NvimView { } let bufferHandle = array[1] -// bridgeLogger.debug("\(event) -> \(bufferHandle)") +// self.bridgeLogger.debug("\(event) -> \(bufferHandle)") if event == .bufwinenter || event == .bufwinleave { self.bufferListChanged() @@ -161,12 +161,12 @@ extension NvimView { } final func ipcBecameInvalid(_ reason: String) { - bridgeLogger.debug(reason) + self.bridgeLogger.debug(reason) self.eventsSubject.onNext(.ipcBecameInvalid(reason)) self.eventsSubject.onCompleted() - bridgeLogger.error("Force-closing due to IPC error.") + self.bridgeLogger.error("Force-closing due to IPC error.") try? self.api .stop() .andThen(self.bridge.forceQuit()) @@ -195,7 +195,7 @@ extension NvimView { return } -// bridgeLogger.trace( +// self.bridgeLogger.trace( // "row: \(row), startCol: \(startCol), endCol: \(endCol), " + // "clearCol: \(clearCol), clearAttr: \(clearAttr), " + // "chunk: \(chunk), attrIds: \(attrIds)" @@ -237,7 +237,7 @@ extension NvimView { } private func doGoto(position: Position) { - bridgeLogger.debug(position) + self.bridgeLogger.debug(position) // Re-render the old cursor position. self.markForRender( @@ -251,7 +251,7 @@ extension NvimView { } private func doScroll(_ array: [Int]) { - bridgeLogger.debug("[top, bot, left, right, rows, cols] = \(array)") + self.bridgeLogger.debug("[top, bot, left, right, rows, cols] = \(array)") let (top, bottom, left, right, rows, cols) = (array[0], array[1] - 1, array[2], array[3] - 1, array[4], array[5]) @@ -277,7 +277,7 @@ extension NvimView { extension NvimView { final func bell() { - bridgeLogger.mark() + self.bridgeLogger.mark() NSSound.beep() } @@ -285,7 +285,7 @@ extension NvimView { final func cwdChanged(_ value: MessagePackValue) { guard let cwd = value.stringValue else { return } - bridgeLogger.debug(cwd) + self.bridgeLogger.debug(cwd) self._cwd = URL(fileURLWithPath: cwd) self.eventsSubject.onNext(.cwdChanged) } @@ -298,7 +298,7 @@ extension NvimView { } let theme = Theme(values) - bridgeLogger.debug(theme) + self.bridgeLogger.debug(theme) gui.async { self.theme = theme @@ -313,7 +313,7 @@ extension NvimView { return } - bridgeLogger.trace(values) + self.bridgeLogger.trace(values) let attrs = CellAttributes( fontTrait: [], @@ -336,7 +336,7 @@ extension NvimView { final func setDirty(with value: MessagePackValue) { guard let dirty = value.boolValue else { return } - bridgeLogger.debug(dirty) + self.bridgeLogger.debug(dirty) self.eventsSubject.onNext(.setDirtyStatus(dirty)) } @@ -352,7 +352,7 @@ extension NvimView { let reverse = array[5].boolValue else { - bridgeLogger.error("Could not get highlight attributes from " + + self.bridgeLogger.error("Could not get highlight attributes from " + "\(value)") return } @@ -366,7 +366,7 @@ extension NvimView { reverse: reverse ) - bridgeLogger.trace("\(id) -> \(attrs)") + self.bridgeLogger.trace("\(id) -> \(attrs)") gui.async { self.cellAttributesCollection.set(attributes: attrs, for: id) @@ -374,31 +374,31 @@ extension NvimView { } final func updateMenu() { - bridgeLogger.mark() + self.bridgeLogger.mark() } final func busyStart() { - bridgeLogger.mark() + self.bridgeLogger.mark() } final func busyStop() { - bridgeLogger.mark() + self.bridgeLogger.mark() } final func mouseOn() { - bridgeLogger.mark() + self.bridgeLogger.mark() } final func mouseOff() { - bridgeLogger.mark() + self.bridgeLogger.mark() } final func visualBell() { - bridgeLogger.mark() + self.bridgeLogger.mark() } final func suspend() { - bridgeLogger.mark() + self.bridgeLogger.mark() } } diff --git a/NvimView/NvimView/NvimView.swift b/NvimView/NvimView/NvimView.swift index 582e6fd3..0fc95e78 100644 --- a/NvimView/NvimView/NvimView.swift +++ b/NvimView/NvimView/NvimView.swift @@ -279,7 +279,7 @@ public class NvimView: NSView, self.defaultColorsChanged(value) case let .optionSet(value): - bridgeLogger.debug(value) + self.bridgeLogger.debug(value) break case let .autoCommandEvent(value): @@ -364,6 +364,12 @@ public class NvimView: NSView, var markedPosition = Position.null var markedRangeOnScreen: NSRange? + let bridgeLogger = LogContext.fileLogger( + as: "NvimView-Bridge", + with: URL(fileURLWithPath: "/tmp/nvv-bridge.log"), + shouldLogDebug: nil + ) + // MARK: - Private private var _linespacing = NvimView.defaultLinespacing } diff --git a/NvimView/NvimView/Runs.swift b/NvimView/NvimView/Runs.swift index 6f282575..faae2eed 100644 --- a/NvimView/NvimView/Runs.swift +++ b/NvimView/NvimView/Runs.swift @@ -9,7 +9,7 @@ struct AttributesRun { var location: CGPoint var cells: ArraySlice - let attrs: CellAttributes + var attrs: CellAttributes } struct FontGlyphRun {