Skip to content

Commit

Permalink
Sessions can control the clipboard during suspend / restore
Browse files Browse the repository at this point in the history
Fixes #1205
  • Loading branch information
Carlos Cabanero committed May 15, 2023
1 parent a870b2e commit daa9a83
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Blink/TermController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ extension TermController: SuspendableSession {
if view.bounds.size != _sessionParams.viewSize {
_session?.sigwinch()
}

_termView.setClipboardWrite(true)
}

func suspendedSession(with archiver: NSKeyedArchiver) {
Expand All @@ -527,6 +529,7 @@ extension TermController: SuspendableSession {
return
}

_termView.setClipboardWrite(false)
_sessionParams.cleanEncodedState()
session.suspend()

Expand Down
5 changes: 5 additions & 0 deletions Blink/TermJS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
1 change: 1 addition & 0 deletions Blink/TermView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions Blink/TermView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
3 changes: 3 additions & 0 deletions KB/Native/Views/KBWebViewBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
12 changes: 12 additions & 0 deletions Resources/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit daa9a83

Please sign in to comment.