Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion guacamole-common-js/src/main/webapp/modules/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ Guacamole.Keyboard = function Keyboard(element) {
var keycodeKeysyms = {
8: [0xFF08], // backspace
9: [0xFF09], // tab
// 10 (LF) intentionally absent: no physical key generates a linefeed.
12: [0xFF0B, 0xFF0B, 0xFF0B, 0xFFB5], // clear / KP 5
13: [0xFF0D], // enter
16: [0xFFE1, 0xFFE1, 0xFFE2], // shift
Expand Down Expand Up @@ -1060,7 +1061,31 @@ Guacamole.Keyboard = function Keyboard(element) {
if (str.charCodeAt(i) !== codepoint) {
i++;
}
var keysym = keysym_from_charcode(codepoint);

// CR and LF are handled explicitly; all other codepoints go through
// keysym_from_charcode().
var keysym;

if (codepoint === 0x0D) {
keysym = 0xFF0D;

// CRLF pairs are collapsed to produce a single Return.
var nextCodepoint = (i + 1 < str.length)
? (str.codePointAt ? str.codePointAt(i + 1) : str.charCodeAt(i + 1))
: 0;

if (nextCodepoint === 0x0A)
i++;
}
else if (codepoint === 0x0A) {
// keysym_from_charcode(0x0A) would return 0xFF0A which is not
// a keyboard character and is ignored by protocol input
// handlers.
keysym = 0xFF0D;
}
else {
keysym = keysym_from_charcode(codepoint);
}

// Press and release key for current character
guac_keyboard.press(keysym);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,35 @@ angular.module('textInput').directive('guacTextInput', [function guacTextInput()

};

// Handle paste separately from normal input.
target.addEventListener("paste", function targetPaste(e) {

if (!e.clipboardData)
return;

// Take over paste handling before the browser inserts anything.
e.preventDefault();
e.stopPropagation();

var content = e.clipboardData.getData('text/plain');

// Normalize line endings to \n.
content = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');

// Release modifiers so pasted text isn't treated as Ctrl/Alt combos.
$rootScope.$broadcast('guacSyntheticKeyup', 0xFFE3); // Left Ctrl
$rootScope.$broadcast('guacSyntheticKeyup', 0xFFE4); // Right Ctrl
$rootScope.$broadcast('guacSyntheticKeyup', 0xFFE9); // Left Alt
$rootScope.$broadcast('guacSyntheticKeyup', 0xFFEA); // Right Alt

sendString(content);

releaseStickyKeys();

// Reset the text input box to its normal padded cursor position.
resetTextInputTarget(TEXT_INPUT_PADDING);

}, false);
target.addEventListener("input", function(e) {

// Ignore input events during text composition
Expand Down