mirror of
https://github.com/h3pdesign/Neon-Vision-Editor
synced 2026-04-21 13:27:16 +00:00
Fix stale tab bindings crash and smooth highlighting for big files
This commit is contained in:
parent
81bb498cda
commit
4819662e9a
3 changed files with 21 additions and 11 deletions
|
|
@ -358,7 +358,7 @@
|
|||
CODE_SIGNING_ALLOWED = YES;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 304;
|
||||
CURRENT_PROJECT_VERSION = 305;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEVELOPMENT_TEAM = CS727NF72U;
|
||||
ENABLE_APP_SANDBOX = YES;
|
||||
|
|
@ -439,7 +439,7 @@
|
|||
CODE_SIGNING_ALLOWED = YES;
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 304;
|
||||
CURRENT_PROJECT_VERSION = 305;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEVELOPMENT_TEAM = CS727NF72U;
|
||||
ENABLE_APP_SANDBOX = YES;
|
||||
|
|
|
|||
|
|
@ -1811,11 +1811,13 @@ struct ContentView: View {
|
|||
// Bindings that resolve to the active tab (if present) or fallback single-document state.
|
||||
var currentContentBinding: Binding<String> {
|
||||
if let selectedID = viewModel.selectedTabID,
|
||||
let idx = viewModel.tabs.firstIndex(where: { $0.id == selectedID }) {
|
||||
viewModel.tabs.contains(where: { $0.id == selectedID }) {
|
||||
return Binding(
|
||||
get: { viewModel.tabs[idx].content },
|
||||
get: {
|
||||
viewModel.tabs.first(where: { $0.id == selectedID })?.content ?? singleContent
|
||||
},
|
||||
set: { newValue in
|
||||
let tab = viewModel.tabs[idx]
|
||||
guard let tab = viewModel.tabs.first(where: { $0.id == selectedID }) else { return }
|
||||
viewModel.updateTabContent(tab: tab, content: newValue)
|
||||
}
|
||||
)
|
||||
|
|
@ -1825,10 +1827,15 @@ struct ContentView: View {
|
|||
}
|
||||
|
||||
var currentLanguageBinding: Binding<String> {
|
||||
if let selectedID = viewModel.selectedTabID, let idx = viewModel.tabs.firstIndex(where: { $0.id == selectedID }) {
|
||||
if let selectedID = viewModel.selectedTabID, viewModel.tabs.contains(where: { $0.id == selectedID }) {
|
||||
return Binding(
|
||||
get: { viewModel.tabs[idx].language },
|
||||
set: { newValue in viewModel.tabs[idx].language = newValue }
|
||||
get: {
|
||||
viewModel.tabs.first(where: { $0.id == selectedID })?.language ?? singleLanguage
|
||||
},
|
||||
set: { newValue in
|
||||
guard let tab = viewModel.tabs.first(where: { $0.id == selectedID }) else { return }
|
||||
viewModel.updateTabLanguage(tab: tab, language: newValue)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
return $singleLanguage
|
||||
|
|
|
|||
|
|
@ -2318,8 +2318,9 @@ struct CustomTextEditor: NSViewRepresentable {
|
|||
}()
|
||||
NotificationCenter.default.post(name: .caretPositionDidChange, object: nil, userInfo: ["line": line, "column": col])
|
||||
if triggerHighlight {
|
||||
// Caret/line feedback should feel immediate while navigating with mouse/keyboard.
|
||||
scheduleHighlightIfNeeded(currentText: tv.string, immediate: true)
|
||||
// For very large files, avoid immediate full caret-triggered passes to keep UI responsive.
|
||||
let immediateHighlight = ns.length < 200_000
|
||||
scheduleHighlightIfNeeded(currentText: tv.string, immediate: immediateHighlight)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3075,7 +3076,9 @@ struct CustomTextEditor: UIViewRepresentable {
|
|||
|
||||
func textViewDidChangeSelection(_ textView: UITextView) {
|
||||
guard !isApplyingHighlight else { return }
|
||||
scheduleHighlightIfNeeded(currentText: textView.text, immediate: true)
|
||||
let nsLength = (textView.text as NSString?)?.length ?? 0
|
||||
let immediateHighlight = nsLength < 200_000
|
||||
scheduleHighlightIfNeeded(currentText: textView.text, immediate: immediateHighlight)
|
||||
}
|
||||
|
||||
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
|
||||
|
|
|
|||
Loading…
Reference in a new issue