diff --git a/Blink/TermController.swift b/Blink/TermController.swift index b2d3a85e9..6e33bfaa4 100644 --- a/Blink/TermController.swift +++ b/Blink/TermController.swift @@ -518,6 +518,8 @@ extension TermController: SuspendableSession { if view.bounds.size != _sessionParams.viewSize { _session?.sigwinch() } + + _termView.setClipboardWrite(true) } func suspendedSession(with archiver: NSKeyedArchiver) { @@ -527,6 +529,7 @@ extension TermController: SuspendableSession { return } + _termView.setClipboardWrite(false) _sessionParams.cleanEncodedState() session.suspend() diff --git a/Blink/TermJS.h b/Blink/TermJS.h index 4c6bdcec0..00c81a82f 100644 --- a/Blink/TermJS.h +++ b/Blink/TermJS.h @@ -141,6 +141,11 @@ NSString *term_setBoldEnabled(NSUInteger state) return [NSString stringWithFormat:@"term_set('enable-bold', %@);", stateStr]; } +NSString *term_setClipboardWrite(BOOL state) +{ + return [NSString stringWithFormat:@"term_setClipboardWrite(%@);", state ? @"true" : @"false"]; +} + NSString *term_setFontFamily(NSString *family, NSString * fontSizeDetectionMethod) { return [NSString stringWithFormat:@"term_setFontFamily(%@, %@);", _encodeString(family), _encodeString(fontSizeDetectionMethod)]; diff --git a/Blink/TermView.h b/Blink/TermView.h index 1355a2904..00c80ce6a 100644 --- a/Blink/TermView.h +++ b/Blink/TermView.h @@ -89,6 +89,7 @@ extern NSString * TermViewBrowserReadyNotificationKey; - (void)setCursorBlink:(BOOL)state; - (void)setBoldAsBright:(BOOL)state; - (void)setBoldEnabled:(NSUInteger)state; +- (void)setClipboardWrite:(BOOL)state; - (void)applyTheme:(NSString *)themeName; - (void)copy:(id _Nullable )sender; - (void)pasteSelection:(id _Nullable)sender; diff --git a/Blink/TermView.m b/Blink/TermView.m index 6bce2f705..132536ff3 100644 --- a/Blink/TermView.m +++ b/Blink/TermView.m @@ -470,6 +470,10 @@ - (void)resetFontSize [_webView evaluateJavaScript:term_resetFontSize() completionHandler:nil]; } +- (void)setClipboardWrite:(BOOL)state { + [_webView evaluateJavaScript:term_setClipboardWrite(state) completionHandler:nil]; +} + - (void)focus { _gestureInteraction.focused = YES; // [_webView evaluateJavaScript:term_focus() completionHandler:nil]; diff --git a/KB/Native/Views/KBWebViewBase.m b/KB/Native/Views/KBWebViewBase.m index 6d2173e41..a5fa07247 100644 --- a/KB/Native/Views/KBWebViewBase.m +++ b/KB/Native/Views/KBWebViewBase.m @@ -159,6 +159,9 @@ - (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguratio _focused = NO; [self.configuration.userContentController addScriptMessageHandler:self name:_interopName]; self.configuration.defaultWebpagePreferences.preferredContentMode = WKContentModeDesktop; + if (@available(iOS 16.4, *)) { + self.inspectable = true; + } // [self.configuration.preferences setJavaScriptCanOpenWindowsAutomatically:true]; NSMutableArray *imeGuards = [[NSMutableArray alloc] init]; diff --git a/Resources/term.js b/Resources/term.js index eafa329d8..60b12af15 100644 --- a/Resources/term.js +++ b/Resources/term.js @@ -338,6 +338,18 @@ function term_setFontFamily(name, fontSizeDetectionMethod) { term_set('font-family', name + ', "DejaVu Sans Mono"'); } +function term_setClipboardWrite(state) { + if (state === false) { + t.vt.enableClipboardWrite = false; + } else { + setTimeout(() => { + // Delay a tiny bit so operations that reset the clipboard + // can have a tiny bit more margin. #1205 + t.vt.enableClipboardWrite = true; + }, 500); + } +} + function term_appendUserCss(css) { var style = document.createElement('style');