UNPKG

@inst/vscode-bin-darwin

Version:

BINARY ONLY - VSCode binary deployment for macOS

126 lines (124 loc) 5.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var CompositionHelper = (function () { function CompositionHelper(textarea, compositionView, terminal) { this.textarea = textarea; this.compositionView = compositionView; this.terminal = terminal; this.isComposing = false; this.isSendingComposition = false; this.compositionPosition = { start: null, end: null }; } CompositionHelper.prototype.compositionstart = function () { this.isComposing = true; this.compositionPosition.start = this.textarea.value.length; this.compositionView.textContent = ''; this.compositionView.classList.add('active'); }; CompositionHelper.prototype.compositionupdate = function (ev) { var _this = this; this.compositionView.textContent = ev.data; this.updateCompositionElements(); setTimeout(function () { _this.compositionPosition.end = _this.textarea.value.length; }, 0); }; CompositionHelper.prototype.compositionend = function () { this.finalizeComposition(true); }; CompositionHelper.prototype.keydown = function (ev) { if (this.isComposing || this.isSendingComposition) { if (ev.keyCode === 229) { return false; } else if (ev.keyCode === 16 || ev.keyCode === 17 || ev.keyCode === 18) { return false; } else { this.finalizeComposition(false); } } if (ev.keyCode === 229) { this.handleAnyTextareaChanges(); return false; } return true; }; CompositionHelper.prototype.finalizeComposition = function (waitForPropogation) { var _this = this; this.compositionView.classList.remove('active'); this.isComposing = false; this.clearTextareaPosition(); if (!waitForPropogation) { this.isSendingComposition = false; var input = this.textarea.value.substring(this.compositionPosition.start, this.compositionPosition.end); this.terminal.handler(input); } else { var currentCompositionPosition_1 = { start: this.compositionPosition.start, end: this.compositionPosition.end, }; this.isSendingComposition = true; setTimeout(function () { if (_this.isSendingComposition) { _this.isSendingComposition = false; var input = void 0; if (_this.isComposing) { input = _this.textarea.value.substring(currentCompositionPosition_1.start, currentCompositionPosition_1.end); } else { input = _this.textarea.value.substring(currentCompositionPosition_1.start); } _this.terminal.handler(input); } }, 0); } }; CompositionHelper.prototype.handleAnyTextareaChanges = function () { var _this = this; var oldValue = this.textarea.value; setTimeout(function () { if (!_this.isComposing) { var newValue = _this.textarea.value; var diff = newValue.replace(oldValue, ''); if (diff.length > 0) { _this.terminal.handler(diff); } } }, 0); }; CompositionHelper.prototype.updateCompositionElements = function (dontRecurse) { var _this = this; if (!this.isComposing) { return; } if (this.terminal.buffer.isCursorInViewport) { var cellHeight = Math.ceil(this.terminal.charMeasure.height * this.terminal.options.lineHeight); var cursorTop = this.terminal.buffer.y * cellHeight; var cursorLeft = this.terminal.buffer.x * this.terminal.charMeasure.width; this.compositionView.style.left = cursorLeft + 'px'; this.compositionView.style.top = cursorTop + 'px'; this.compositionView.style.height = cellHeight + 'px'; this.compositionView.style.lineHeight = cellHeight + 'px'; var compositionViewBounds = this.compositionView.getBoundingClientRect(); this.textarea.style.left = cursorLeft + 'px'; this.textarea.style.top = cursorTop + 'px'; this.textarea.style.width = compositionViewBounds.width + 'px'; this.textarea.style.height = compositionViewBounds.height + 'px'; this.textarea.style.lineHeight = compositionViewBounds.height + 'px'; } if (!dontRecurse) { setTimeout(function () { return _this.updateCompositionElements(true); }, 0); } }; ; CompositionHelper.prototype.clearTextareaPosition = function () { this.textarea.style.left = ''; this.textarea.style.top = ''; }; ; return CompositionHelper; }()); exports.CompositionHelper = CompositionHelper; //# sourceMappingURL=CompositionHelper.js.map