1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-12-29 16:56:40 +03:00

Do not set cursor when writing non-Markdown files.

This commit is contained in:
Tae Won Ha 2017-12-17 19:24:12 +01:00
parent bf6c38969a
commit 0bf4480799
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44
4 changed files with 31 additions and 11 deletions

View File

@ -231,8 +231,8 @@ class MainWindow: NSObject,
if let cwd = state.cwdToSet {
self.neoVimView.cwd = cwd
}
if state.previewTool.isReverseSearchAutomatically
if state.preview.status == .markdown
&& state.previewTool.isReverseSearchAutomatically
&& state.preview.previewPosition.hasDifferentMark(as: self.previewPosition) {
self.neoVimView.cursorGo(to: state.preview.previewPosition.payload)
}

View File

@ -109,7 +109,10 @@ class MarkdownReducer {
state.preview.lastSearch = .none // .none because the forward search does not invoke .scroll above.
case .close:
state.preview = PreviewUtils.state(for: .none, baseUrl: self.baseServerUrl)
state.preview = PreviewUtils.state(for: .none,
baseUrl: self.baseServerUrl,
editorPosition: state.preview.editorPosition,
previewPosition: state.preview.previewPosition)
state.preview.lastSearch = .none
default:

View File

@ -88,7 +88,8 @@ class PreviewTool: NSView, UiComponent, WKNavigationDelegate {
self.automaticReverseMenuItem.boolState = state.previewTool.isReverseSearchAutomatically
self.refreshOnWriteMenuItem.boolState = state.previewTool.isRefreshOnWrite
if state.previewTool.isForwardSearchAutomatically
if state.preview.status == .markdown
&& state.previewTool.isForwardSearchAutomatically
&& state.preview.editorPosition.hasDifferentMark(as: self.editorPosition)
{
self.forwardSearch(position: state.preview.editorPosition.payload)

View File

@ -9,20 +9,30 @@ fileprivate let markdownPath = "tools/preview/markdown"
class PreviewUtils {
static func state(for status: PreviewState.Status, baseUrl: URL) -> PreviewState {
static func state(for status: PreviewState.Status,
baseUrl: URL,
editorPosition: Marked<Position>,
previewPosition: Marked<Position>) -> PreviewState {
switch status {
case .none:
return PreviewState(status: .none,
server: self.simpleServerUrl(with: MarkdownReducer.nonePath, baseUrl: baseUrl))
server: self.simpleServerUrl(with: MarkdownReducer.nonePath, baseUrl: baseUrl),
editorPosition: editorPosition,
previewPosition: previewPosition)
case .error:
return PreviewState(status: .error,
server: self.simpleServerUrl(with: MarkdownReducer.errorPath, baseUrl: baseUrl))
server: self.simpleServerUrl(with: MarkdownReducer.errorPath, baseUrl: baseUrl),
editorPosition: editorPosition,
previewPosition: previewPosition)
case .notSaved:
return PreviewState(status: .notSaved,
server: self.simpleServerUrl(with: MarkdownReducer.saveFirstPath, baseUrl: baseUrl))
server: self.simpleServerUrl(with: MarkdownReducer.saveFirstPath, baseUrl: baseUrl),
editorPosition: editorPosition,
previewPosition: previewPosition)
case .markdown:
preconditionFailure("ERROR Use the other previewState()!")
@ -37,15 +47,21 @@ class PreviewUtils {
previewPosition: Marked<Position>) -> PreviewState {
guard let url = buffer?.url else {
return self.state(for: .notSaved, baseUrl: baseUrl)
return self.state(
for: .notSaved, baseUrl: baseUrl, editorPosition: editorPosition, previewPosition: previewPosition
)
}
guard FileUtils.fileExists(at: url) else {
return self.state(for: .error, baseUrl: baseUrl)
return self.state(
for: .error, baseUrl: baseUrl, editorPosition: editorPosition, previewPosition: previewPosition
)
}
guard self.extensions.contains(url.pathExtension) else {
return self.state(for: .none, baseUrl: baseUrl)
return self.state(
for: .none, baseUrl: baseUrl, editorPosition: editorPosition, previewPosition: previewPosition
)
}
return PreviewState(status: .markdown,