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:
parent
bf6c38969a
commit
0bf4480799
@ -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)
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user