提交 dd741194 编写于 作者: A Alex Dima

Remove TextAreaState.extractNewText() and extractMacReplacedText()

上级 a1bd50f6
......@@ -172,56 +172,6 @@ export abstract class TextAreaState {
replaceCharCnt: replacePreviousCharacters
};
}
public extractNewText(): string {
// console.log('-----------')
// console.log('prev:' + String(previousState));
// console.log('curr:' + String(this));
if (this.selectionStart !== this.selectionEnd) {
// There is a selection in the textarea => ignore input
return '';
}
if (!this.previousState) {
return this.value;
}
let previousPrefix = this.previousState.value.substring(0, this.previousState.selectionStart);
let previousSuffix = this.previousState.value.substring(this.previousState.selectionEnd, this.previousState.value.length);
if (this.isInOverwriteMode) {
previousSuffix = previousSuffix.substr(1);
}
let value = this.value;
if (value.substring(0, previousPrefix.length) === previousPrefix) {
value = value.substring(previousPrefix.length);
}
if (value.substring(value.length - previousSuffix.length, value.length) === previousSuffix) {
value = value.substring(0, value.length - previousSuffix.length);
}
return value;
}
public extractMacReplacedText(): string {
// Ignore if the textarea has selection
if (this.selectionStart !== this.selectionEnd) {
return '';
}
if (!this.previousState) {
return '';
}
if (this.previousState.value.length !== this.value.length) {
return '';
}
let prefixLength = commonPrefixLength(this.previousState.value, this.value);
let suffixLength = commonSuffixLength(this.previousState.value, this.value);
if (prefixLength + suffixLength + 1 !== this.value.length) {
return '';
}
return this.value.charAt(prefixLength);
}
}
export class IENarratorTextAreaState extends TextAreaState {
......
......@@ -221,161 +221,129 @@ suite('TextAreaState', () => {
);
});
function testExtractNewText(prevState:TextAreaState, value:string, selectionStart:number, selectionEnd:number, isInOverwriteMode: boolean, expected:string): void {
let textArea = new MockTextAreaWrapper();
textArea._value = value;
textArea._selectionStart = selectionStart;
textArea._selectionEnd = selectionEnd;
textArea._isInOverwriteMode = isInOverwriteMode;
let newState = (prevState || IENarratorTextAreaState.EMPTY).fromTextArea(textArea);
let actual = newState.extractNewText();
assert.equal(actual, expected);
textArea.dispose();
}
test('extractNewText - no previous state with selection', () => {
testExtractNewText(
testDeduceInput(
null,
'a',
0, 1, false,
''
'a', 0
);
});
test('extractNewText - no previous state without selection', () => {
testExtractNewText(
testDeduceInput(
null,
'a',
1, 1, false,
'a'
'a', 0
);
});
test('extractNewText - typing does not cause a selection', () => {
testExtractNewText(
testDeduceInput(
new IENarratorTextAreaState(null, '', 0, 0, false, 0),
'a',
0, 1, false,
''
'a', 0
);
});
test('extractNewText - had the textarea empty', () => {
testExtractNewText(
testDeduceInput(
new IENarratorTextAreaState(null, '', 0, 0, false, 0),
'a',
1, 1, false,
'a'
'a', 0
);
});
test('extractNewText - had the entire line selected', () => {
testExtractNewText(
testDeduceInput(
new IENarratorTextAreaState(null, 'Hello world!', 0, 12, false, 0),
'H',
1, 1, false,
'H'
'H', 0
);
});
test('extractNewText - had previous text 1', () => {
testExtractNewText(
testDeduceInput(
new IENarratorTextAreaState(null, 'Hello world!', 12, 12, false, 0),
'Hello world!a',
13, 13, false,
'a'
'a', 0
);
});
test('extractNewText - had previous text 2', () => {
testExtractNewText(
testDeduceInput(
new IENarratorTextAreaState(null, 'Hello world!', 0, 0, false, 0),
'aHello world!',
1, 1, false,
'a'
'a', 0
);
});
test('extractNewText - had previous text 3', () => {
testExtractNewText(
testDeduceInput(
new IENarratorTextAreaState(null, 'Hello world!', 6, 11, false, 0),
'Hello other!',
11, 11, false,
'other'
'other', 0
);
});
test('extractNewText - IME', () => {
testExtractNewText(
testDeduceInput(
new IENarratorTextAreaState(null, '', 0, 0, false, 0),
'これは',
3, 3, false,
'これは'
'これは', 0
);
});
test('extractNewText - isInOverwriteMode', () => {
testExtractNewText(
testDeduceInput(
new IENarratorTextAreaState(null, 'Hello world!', 0, 0, false, 0),
'Aello world!',
1, 1, true,
'A'
'A', 0
);
});
function testExtractMacReplacedText(prevState:TextAreaState, value:string, selectionStart:number, selectionEnd:number, isInOverwriteMode: boolean, expected:string): void {
let textArea = new MockTextAreaWrapper();
textArea._value = value;
textArea._selectionStart = selectionStart;
textArea._selectionEnd = selectionEnd;
textArea._isInOverwriteMode = isInOverwriteMode;
let newState = (prevState || IENarratorTextAreaState.EMPTY).fromTextArea(textArea);
let actual = newState.extractMacReplacedText();
assert.equal(actual, expected);
textArea.dispose();
}
test('extractMacReplacedText - does nothing if there is selection', () => {
testExtractMacReplacedText(
new IENarratorTextAreaState(null, 'Hello world!', 0, 0, false, 0),
testDeduceInput(
new IENarratorTextAreaState(null, 'Hello world!', 5, 5, false, 0),
'Hellö world!',
4, 5, false,
''
'ö', 0
);
});
test('extractMacReplacedText - does nothing if there is more than one extra char', () => {
testExtractMacReplacedText(
new IENarratorTextAreaState(null, 'Hello world!', 0, 0, false, 0),
testDeduceInput(
new IENarratorTextAreaState(null, 'Hello world!', 5, 5, false, 0),
'Hellöö world!',
6, 6, false,
''
5, 5, false,
'öö', 1
);
});
test('extractMacReplacedText - does nothing if there is more than one changed char', () => {
testExtractMacReplacedText(
new IENarratorTextAreaState(null, 'Hello world!', 0, 0, false, 0),
testDeduceInput(
new IENarratorTextAreaState(null, 'Hello world!', 5, 5, false, 0),
'Helöö world!',
6, 6, false,
''
5, 5, false,
'öö', 2
);
});
test('extractMacReplacedText', () => {
testExtractMacReplacedText(
new IENarratorTextAreaState(null, 'Hello world!', 0, 0, false, 0),
testDeduceInput(
new IENarratorTextAreaState(null, 'Hello world!', 5, 5, false, 0),
'Hellö world!',
5, 5, false,
'ö'
'ö', 1
);
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册