mike-jumper commented on code in PR #908:
URL: https://github.com/apache/guacamole-client/pull/908#discussion_r1338861222
##########
guacamole-common-js/src/main/webapp/modules/KeyEventInterpreter.js:
##########
@@ -424,6 +452,29 @@ Guacamole.KeyEventInterpreter = function
KeyEventInterpreter(batchSeperation, st
var keyText;
var typed;
+ // If this key should be both printed and rendered
+ if (keyDefinition.value != null &&
keyDefinition.printAndRender) {
+
+ // The printed name of the key
+ var printedValue = getPrintedKeyName(keyDefinition);
+
+ // The directly rendered value
+ var renderedValue = keyDefinition.value;
+
+ // Display the name first, followed by the value
+ currentBatch.simpleValue += printedValue;
+ currentBatch.simpleValue += renderedValue;
+
+ // Add pair of key events in the same order, with the name
+ // displayed as non-typed to ensure proper styling
+ currentBatch.events.push(new
Guacamole.KeyEventInterpreter.KeyEvent(
+ printedValue, false, relativeTimestap));
+ currentBatch.events.push(new
Guacamole.KeyEventInterpreter.KeyEvent(
+ renderedValue, true, relativeTimestap));
Review Comment:
This looks much better to me.
##########
guacamole-common-js/src/main/webapp/modules/KeyEventInterpreter.js:
##########
@@ -460,91 +253,85 @@ Guacamole.KeyEventInterpreter = function
KeyEventInterpreter(batchSeperation, st
* incomplete, as more key events might be processed before the next
* batch starts.
*
- * @returns {Guacamole.KeyEventInterpreter.KeyEventBatch}
+ * @returns {Guacamole.KeyEventInterpreter.KeyEvent[]}
* The current batch of text.
*/
- this.getCurrentBatch = function getCurrentBatch() {
- return currentBatch;
+ this.getEvents = function getEvents() {
+ return parsedEvents;
};
+
};
/**
- * A granular description of an extracted key event, including a human-readable
- * text representation of the event, whether the event is directly typed or
not,
- * and the timestamp when the event occured.
+ * A definition for a known key.
*
* @constructor
- * @param {!String} text
- * A human-readable representation of the event.
- *
- * @param {!boolean} typed
- * True if this event represents a directly-typed character, or false
- * otherwise.
- *
- * @param {!Number} timestamp
- * The timestamp from the recording when this event occured.
+ * @private
+ * @param {Guacamole.KeyEventInterpreter.KeyDefinition|object} [template={}]
+ * The object whose properties should be copied within the new
+ * KeyDefinition.
*/
-Guacamole.KeyEventInterpreter.KeyEvent = function KeyEvent(text, typed,
timestamp) {
+Guacamole.KeyEventInterpreter.KeyDefinition = function KeyDefinition(template)
{
+
+ // Use empty object by default
+ template = template || {};
/**
- * A human-readable representation of the event. If a printable character
- * was directly typed, this will just be that character. Otherwise it will
- * be a string describing the event.
- *
- * @type {!String}
+ * The X11 keysym of the key.
+ * @type {!number}
*/
- this.text = text;
+ this.keysym = parseInt(template.keysym);
/**
- * True if this text of this event is exactly a typed character, or false
- * otherwise.
- *
- * @type {!boolean}
+ * A human-readable name for the key.
+ * @type {!String}
*/
- this.typed = typed;
+ this.name = template.name;
/**
- * The timestamp from the recording when this event occured. If a
- * `startTimestamp` value was provided to the interpreter constructor, this
- * will be relative to start of the recording. If not, it will be the raw
- * timestamp from the key event.
- *
- * @type {!Number}
+ * The value which would be typed in a typical text editor, if any. If the
+ * key is not associated with any typeable value, this will be undefined.
+ * @type {String}
*/
- this.timestamp = timestamp;
+ this.value = template.value;
};
/**
- * A series of intepreted key events, seperated by at least the configured
- * batchSeperation value from any other key events in the recording
corresponding
- * to the interpreted key events. A batch will always consist of at least one
key
- * event, and an associated simplified representation of the event(s).
+ * A granular description of an extracted key event, including a human-readable
+ * text representation of the event, whether the event is directly typed or
not,
+ * and the timestamp when the event occured.
*
* @constructor
- * @param {!Guacamole.KeyEventInterpreter.KeyEvent[]} events
- * The interpreted key events for this batch.
- *
- * @param {!String} simpleValue
- * The simplified, human-readable value representing the key events for
- * this batch.
+ * @param {Guacamole.KeyEventInterpreter.KeyDefinition|object} [template={}]
+ * The object whose properties should be copied within the new
+ * KeyDefinition.
*/
-Guacamole.KeyEventInterpreter.KeyEventBatch = function KeyEventBatch(events,
simpleValue) {
+Guacamole.KeyEventInterpreter.KeyEvent = function KeyEvent(template) {
+
+ // Use empty object by default
+ template = template || {};
/**
- * All key events for this batch.
+ * The key definition for the pressed key.
*
- * @type {!Guacamole.KeyEventInterpreter.KeyEvent[]}
+ * @type {!Guacamole.KeyEventInterpreter.KeyDefinition}
*/
- this.events = events || [];
+ this.definition = template.definition;
Review Comment:
`Guacamole.KeyEventInterpreter.KeyDefinition` is marked as `@private`, but
this property is public.
##########
guacamole-common-js/src/main/webapp/modules/KeyEventInterpreter.js:
##########
@@ -460,91 +253,85 @@ Guacamole.KeyEventInterpreter = function
KeyEventInterpreter(batchSeperation, st
* incomplete, as more key events might be processed before the next
* batch starts.
*
- * @returns {Guacamole.KeyEventInterpreter.KeyEventBatch}
+ * @returns {Guacamole.KeyEventInterpreter.KeyEvent[]}
* The current batch of text.
*/
- this.getCurrentBatch = function getCurrentBatch() {
- return currentBatch;
+ this.getEvents = function getEvents() {
+ return parsedEvents;
};
+
};
/**
- * A granular description of an extracted key event, including a human-readable
- * text representation of the event, whether the event is directly typed or
not,
- * and the timestamp when the event occured.
+ * A definition for a known key.
*
* @constructor
- * @param {!String} text
- * A human-readable representation of the event.
- *
- * @param {!boolean} typed
- * True if this event represents a directly-typed character, or false
- * otherwise.
- *
- * @param {!Number} timestamp
- * The timestamp from the recording when this event occured.
+ * @private
+ * @param {Guacamole.KeyEventInterpreter.KeyDefinition|object} [template={}]
+ * The object whose properties should be copied within the new
+ * KeyDefinition.
*/
-Guacamole.KeyEventInterpreter.KeyEvent = function KeyEvent(text, typed,
timestamp) {
+Guacamole.KeyEventInterpreter.KeyDefinition = function KeyDefinition(template)
{
+
+ // Use empty object by default
+ template = template || {};
/**
- * A human-readable representation of the event. If a printable character
- * was directly typed, this will just be that character. Otherwise it will
- * be a string describing the event.
- *
- * @type {!String}
+ * The X11 keysym of the key.
+ * @type {!number}
*/
- this.text = text;
+ this.keysym = parseInt(template.keysym);
/**
- * True if this text of this event is exactly a typed character, or false
- * otherwise.
- *
- * @type {!boolean}
+ * A human-readable name for the key.
+ * @type {!String}
*/
- this.typed = typed;
+ this.name = template.name;
/**
- * The timestamp from the recording when this event occured. If a
- * `startTimestamp` value was provided to the interpreter constructor, this
- * will be relative to start of the recording. If not, it will be the raw
- * timestamp from the key event.
- *
- * @type {!Number}
+ * The value which would be typed in a typical text editor, if any. If the
+ * key is not associated with any typeable value, this will be undefined.
+ * @type {String}
*/
- this.timestamp = timestamp;
+ this.value = template.value;
};
/**
- * A series of intepreted key events, seperated by at least the configured
- * batchSeperation value from any other key events in the recording
corresponding
- * to the interpreted key events. A batch will always consist of at least one
key
- * event, and an associated simplified representation of the event(s).
+ * A granular description of an extracted key event, including a human-readable
+ * text representation of the event, whether the event is directly typed or
not,
+ * and the timestamp when the event occured.
*
* @constructor
- * @param {!Guacamole.KeyEventInterpreter.KeyEvent[]} events
- * The interpreted key events for this batch.
- *
- * @param {!String} simpleValue
- * The simplified, human-readable value representing the key events for
- * this batch.
+ * @param {Guacamole.KeyEventInterpreter.KeyDefinition|object} [template={}]
Review Comment:
`Guacamole.KeyEventInterpreter.KeyEvent`*?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]