Skip to content

Commit

Permalink
Fix multiline copy/paste. Fixes blinksh#391
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Apr 26, 2018
1 parent 76d817f commit 0d4be80
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 34 deletions.
13 changes: 2 additions & 11 deletions Blink/TermInput.m
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,7 @@ - (void)toggleUnderline:(id)sender

- (void)pasteSelection:(id)sender
{
NSString *str = _device.view.selectedText;
if (str) {
[_device write:str];
}
[_device.view cleanSelection];
[_device.view pasteSelection: sender];
}

- (void)copyLink:(id)sender
Expand Down Expand Up @@ -1002,12 +998,7 @@ - (BOOL)_capsMapped

- (void)yank:(id)sender
{
NSString *str = [UIPasteboard generalPasteboard].string;

if (str) {
[_device write:str];
}
[_device.view cleanSelection];
[_device.view paste:sender];
}

- (void)_changeSelection:(UIKeyCommand *) cmd
Expand Down
4 changes: 4 additions & 0 deletions Blink/TermJS.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ NSString *term_writeB64(NSData *data) {
return [NSString stringWithFormat:@"term_write_b64(\"%@\");", [data base64EncodedStringWithOptions:kNilOptions]];
}

NSString *term_paste(NSString *str) {
return [NSString stringWithFormat:@"term_paste(%@[0]);", _encodeString(str)];
}

NSString *term_clear()
{
return @"term_clear();";
Expand Down
1 change: 1 addition & 0 deletions Blink/TermView.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
- (void)setBoldEnabled:(NSUInteger)state;
- (void)setIme:(NSString *)imeText completionHandler:(void (^ _Nullable)(_Nullable id, NSError * _Nullable error))completionHandler;
- (void)copy:(id _Nullable )sender;
- (void)pasteSelection:(id _Nullable)sender;
- (void)setAutoCarriageReturn:(BOOL)state;
- (void)terminate;
- (void)reset;
Expand Down
16 changes: 15 additions & 1 deletion Blink/TermView.m
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,28 @@ - (void)yank:(id)sender

- (void)pasteSelection:(id)sender
{

NSString *str = _selectedText;
if (str) {
[_webView evaluateJavaScript:term_paste(str) completionHandler:nil];
}
[self cleanSelection];
}

- (void)copy:(id)sender
{
[_webView copy:sender];
}

- (void)paste:(id)sender
{
NSString *str = [UIPasteboard generalPasteboard].string;
if (str) {
[_webView evaluateJavaScript:term_paste(str) completionHandler:nil];
}

[self cleanSelection];
}

- (NSString *)_detectFontFamilyFromContent:(NSString *)content
{
NSRegularExpression *regex = [NSRegularExpression
Expand Down
4 changes: 2 additions & 2 deletions Resources/hterm_all.min.js

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions Resources/hterm_all.patches.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ hterm.Terminal.prototype.overlaySize = function() {};

hterm.Terminal.prototype.onMouse_ = function() {};

hterm.Terminal.prototype.copyStringToClipboard = function(str) {
if (this.prefs_.get('enable-clipboard-notice')) {
setTimeout(this.showOverlay.bind(this, hterm.notifyCopyMessage, 500), 200);
}

hterm.copySelectionToClipboard(this.document_, str);
};

hterm.Terminal.prototype.copySelectionToClipboard = function() {
const selection = document.getSelection();
if (!selection || selection.rangeCount === 0) {
return;
}

this.copyStringToClipboard(selection.toString());
}

hterm.Terminal.prototype.setCursorVisible = function(state) {
this.options_.cursorVisible = state;
Expand Down
10 changes: 8 additions & 2 deletions Resources/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ function _postMessage(op, data) {
window.webkit.messageHandlers.interOp.postMessage({ op, data });
}

hterm.copySelectionToClipboard = function(document, content) {
hterm.Terminal.prototype.copyStringToClipboard = function(content) {
if (this.prefs_.get('enable-clipboard-notice')) {
setTimeout(this.showOverlay.bind(this, hterm.notifyCopyMessage, 500), 200);
}

document.getSelection().removeAllRanges();
_postMessage('copy', { content });
};


// Speedup a little bit.
hterm.Screen.prototype.syncSelectionCaret = function() {};

Expand Down Expand Up @@ -85,6 +88,9 @@ function term_write(data) {
t.interpret(data);
}

function term_paste(str) {
t.onPaste_({text: str || ""});
}

var term_write_b64 = null;

Expand Down
2 changes: 0 additions & 2 deletions Sessions/SystemSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ - (int)main:(int)argc argv:(char **)argv args:(char *)args
// Redirect all output to console:
ios_setStreams(_stream.in, _stream.out, _stream.out);
int res = ios_system(args);
// get all output back:
// [self _setAutoCarriageReturn:NO];
return res;
}

Expand Down

0 comments on commit 0d4be80

Please sign in to comment.