Merge pull request #508 from Tyriar/507_fix_lint_in_src_root

Run lint on src/*.ts and fix errors
This commit is contained in:
Daniel Imms
2017-01-25 07:30:09 -08:00
committed by GitHub
3 changed files with 33 additions and 36 deletions
+1 -1
View File
@@ -65,7 +65,7 @@
"prestart": "npm run build", "prestart": "npm run build",
"start": "node demo/app", "start": "node demo/app",
"dev": "nodemon -e js,ts --watch src --watch demo --exec npm start", "dev": "nodemon -e js,ts --watch src --watch demo --exec npm start",
"lint": "tslint src/**/*.ts", "lint": "tslint src/*.ts src/**/*.ts",
"test": "mocha --recursive ./lib", "test": "mocha --recursive ./lib",
"build:docs": "jsdoc -c jsdoc.json", "build:docs": "jsdoc -c jsdoc.json",
"build": "gulp build", "build": "gulp build",
+7 -7
View File
@@ -2,11 +2,11 @@ import { assert } from 'chai';
import { CompositionHelper } from './CompositionHelper'; import { CompositionHelper } from './CompositionHelper';
describe('CompositionHelper', () => { describe('CompositionHelper', () => {
var terminal; let terminal;
var compositionHelper; let compositionHelper;
var compositionView; let compositionView;
var textarea; let textarea;
var handledText; let handledText;
beforeEach(() => { beforeEach(() => {
compositionView = { compositionView = {
@@ -125,7 +125,7 @@ describe('CompositionHelper', () => {
compositionHelper.compositionend(); compositionHelper.compositionend();
compositionHelper.compositionstart(); compositionHelper.compositionstart();
compositionHelper.compositionupdate({ data: '아' }); compositionHelper.compositionupdate({ data: '아' });
textarea.value = '아아' textarea.value = '아아';
setTimeout(() => { // wait for any textarea updates setTimeout(() => { // wait for any textarea updates
compositionHelper.compositionend(); compositionHelper.compositionend();
setTimeout(() => { // wait for any textarea updates setTimeout(() => { // wait for any textarea updates
@@ -187,7 +187,7 @@ describe('CompositionHelper', () => {
}, 0); }, 0);
}, 0); }, 0);
}, 0); }, 0);
}) });
it('Should insert multi-character compositions that are converted to other characters with different lengths', function (done) { it('Should insert multi-character compositions that are converted to other characters with different lengths', function (done) {
// First character 'い' // First character 'い'
+25 -28
View File
@@ -24,7 +24,7 @@ export class CompositionHelper {
/** /**
* The position within the input textarea's value of the current composition. * The position within the input textarea's value of the current composition.
*/ */
private compositionPosition: IPosition;; private compositionPosition: IPosition;
/** /**
* Whether a composition is in the process of being sent, setting this to false will cancel any * Whether a composition is in the process of being sent, setting this to false will cancel any
@@ -65,9 +65,8 @@ export class CompositionHelper {
public compositionupdate(ev: CompositionEvent) { public compositionupdate(ev: CompositionEvent) {
this.compositionView.textContent = ev.data; this.compositionView.textContent = ev.data;
this.updateCompositionElements(); this.updateCompositionElements();
var self = this; setTimeout(() => {
setTimeout(function() { this.compositionPosition.end = this.textarea.value.length;
self.compositionPosition.end = self.textarea.value.length;
}, 0); }, 0);
} }
@@ -125,15 +124,15 @@ export class CompositionHelper {
if (!waitForPropogation) { if (!waitForPropogation) {
// Cancel any delayed composition send requests and send the input immediately. // Cancel any delayed composition send requests and send the input immediately.
this.isSendingComposition = false; this.isSendingComposition = false;
var input = this.textarea.value.substring(this.compositionPosition.start, this.compositionPosition.end); const input = this.textarea.value.substring(this.compositionPosition.start, this.compositionPosition.end);
this.terminal.handler(input); this.terminal.handler(input);
} else { } else {
// Make a deep copy of the composition position here as a new compositionstart event may // Make a deep copy of the composition position here as a new compositionstart event may
// fire before the setTimeout executes. // fire before the setTimeout executes.
var currentCompositionPosition = { const currentCompositionPosition = {
start: this.compositionPosition.start, start: this.compositionPosition.start,
end: this.compositionPosition.end, end: this.compositionPosition.end,
} };
// Since composition* events happen before the changes take place in the textarea on most // Since composition* events happen before the changes take place in the textarea on most
// browsers, use a setTimeout with 0ms time to allow the native compositionend event to // browsers, use a setTimeout with 0ms time to allow the native compositionend event to
@@ -143,23 +142,22 @@ export class CompositionHelper {
// - The last compositionupdate event's data property does not always accurately describe // - The last compositionupdate event's data property does not always accurately describe
// the character, a counter example being Korean where an ending consonsant can move to // the character, a counter example being Korean where an ending consonsant can move to
// the following character if the following input is a vowel. // the following character if the following input is a vowel.
var self = this;
this.isSendingComposition = true; this.isSendingComposition = true;
setTimeout(function () { setTimeout(() => {
// Ensure that the input has not already been sent // Ensure that the input has not already been sent
if (self.isSendingComposition) { if (this.isSendingComposition) {
self.isSendingComposition = false; this.isSendingComposition = false;
var input; let input;
if (self.isComposing) { if (this.isComposing) {
// Use the end position to get the string if a new composition has started. // Use the end position to get the string if a new composition has started.
input = self.textarea.value.substring(currentCompositionPosition.start, currentCompositionPosition.end); input = this.textarea.value.substring(currentCompositionPosition.start, currentCompositionPosition.end);
} else { } else {
// Don't use the end position here in order to pick up any characters after the // Don't use the end position here in order to pick up any characters after the
// composition has finished, for example when typing a non-composition character // composition has finished, for example when typing a non-composition character
// (eg. 2) after a composition character. // (eg. 2) after a composition character.
input = self.textarea.value.substring(currentCompositionPosition.start); input = this.textarea.value.substring(currentCompositionPosition.start);
} }
self.terminal.handler(input); this.terminal.handler(input);
} }
}, 0); }, 0);
} }
@@ -172,15 +170,14 @@ export class CompositionHelper {
* IME is active. * IME is active.
*/ */
private handleAnyTextareaChanges() { private handleAnyTextareaChanges() {
var oldValue = this.textarea.value; const oldValue = this.textarea.value;
var self = this; setTimeout(() => {
setTimeout(function() {
// Ignore if a composition has started since the timeout // Ignore if a composition has started since the timeout
if (!self.isComposing) { if (!this.isComposing) {
var newValue = self.textarea.value; const newValue = this.textarea.value;
var diff = newValue.replace(oldValue, ''); const diff = newValue.replace(oldValue, '');
if (diff.length > 0) { if (diff.length > 0) {
self.terminal.handler(diff); this.terminal.handler(diff);
} }
} }
}, 0); }, 0);
@@ -196,12 +193,12 @@ export class CompositionHelper {
if (!this.isComposing) { if (!this.isComposing) {
return; return;
} }
var cursor = <HTMLElement>this.terminal.element.querySelector('.terminal-cursor'); const cursor = <HTMLElement>this.terminal.element.querySelector('.terminal-cursor');
if (cursor) { if (cursor) {
// Take .xterm-rows offsetTop into account as well in case it's positioned absolutely within // Take .xterm-rows offsetTop into account as well in case it's positioned absolutely within
// the .xterm element. // the .xterm element.
var xtermRows = <HTMLElement>this.terminal.element.querySelector('.xterm-rows'); const xtermRows = <HTMLElement>this.terminal.element.querySelector('.xterm-rows');
var cursorTop = xtermRows.offsetTop + cursor.offsetTop; const cursorTop = xtermRows.offsetTop + cursor.offsetTop;
this.compositionView.style.left = cursor.offsetLeft + 'px'; this.compositionView.style.left = cursor.offsetLeft + 'px';
this.compositionView.style.top = cursorTop + 'px'; this.compositionView.style.top = cursorTop + 'px';
@@ -209,7 +206,7 @@ export class CompositionHelper {
this.compositionView.style.lineHeight = cursor.offsetHeight + 'px'; this.compositionView.style.lineHeight = cursor.offsetHeight + 'px';
// Sync the textarea to the exact position of the composition view so the IME knows where the // Sync the textarea to the exact position of the composition view so the IME knows where the
// text is. // text is.
var compositionViewBounds = this.compositionView.getBoundingClientRect(); const compositionViewBounds = this.compositionView.getBoundingClientRect();
this.textarea.style.left = cursor.offsetLeft + 'px'; this.textarea.style.left = cursor.offsetLeft + 'px';
this.textarea.style.top = cursorTop + 'px'; this.textarea.style.top = cursorTop + 'px';
this.textarea.style.width = compositionViewBounds.width + 'px'; this.textarea.style.width = compositionViewBounds.width + 'px';
@@ -217,7 +214,7 @@ export class CompositionHelper {
this.textarea.style.lineHeight = compositionViewBounds.height + 'px'; this.textarea.style.lineHeight = compositionViewBounds.height + 'px';
} }
if (!dontRecurse) { if (!dontRecurse) {
setTimeout(this.updateCompositionElements.bind(this, true), 0); setTimeout(() => this.updateCompositionElements(true), 0);
} }
}; };