[Console][Legacy Editor] Ace Range implementation not being used (#49352)

* Use ace Range implementation, not interface, for instantiating

* Add simple smoke test for use of Ace ranges

* Update test title
This commit is contained in:
Jean-Louis Leysens 2019-10-28 11:47:59 +01:00 committed by GitHub
parent cbe6fd3e3d
commit f868fa66fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 75 additions and 3 deletions

View file

@ -0,0 +1,69 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { Range as AceRange } from 'brace';
import { LegacyEditor } from './legacy_editor';
describe('Legacy Editor', () => {
const aceMock: any = {
getValue() {
return 'ok';
},
getCursorPosition() {
return {
row: 1,
column: 1,
};
},
getSession() {
return {
replace(range: AceRange, value: string) {},
getLine(n: number) {
return 'line';
},
doc: {
getTextRange(r: any) {
return '';
},
},
getState(n: number) {
return n;
},
};
},
};
// This is to ensure that we are correctly importing Ace's Range component
it('smoke tests for updates to ranges', () => {
const legacyEditor = new LegacyEditor(aceMock);
legacyEditor.getValueInRange({
start: { lineNumber: 1, column: 1 },
end: { lineNumber: 2, column: 2 },
});
legacyEditor.replace(
{
start: { lineNumber: 1, column: 1 },
end: { lineNumber: 2, column: 2 },
},
'test!'
);
});
});

View file

@ -17,10 +17,13 @@
* under the License.
*/
import { Editor as IAceEditor, Range as AceRange } from 'brace';
import ace from 'brace';
import { Editor as IAceEditor } from 'brace';
import { CoreEditor, Position, Range, Token, TokensProvider } from '../../types';
import { AceTokensProvider } from '../../lib/ace_token_provider';
const _AceRange = ace.acequire('ace/range').Range;
export class LegacyEditor implements CoreEditor {
constructor(private readonly editor: IAceEditor) {}
@ -31,7 +34,7 @@ export class LegacyEditor implements CoreEditor {
getValueInRange({ start, end }: Range): string {
const session = this.editor.getSession();
const aceRange = new AceRange(
const aceRange = new _AceRange(
start.lineNumber - 1,
start.column - 1,
end.lineNumber - 1,
@ -90,7 +93,7 @@ export class LegacyEditor implements CoreEditor {
}
replace({ start, end }: Range, value: string): void {
const aceRange = new AceRange(
const aceRange = new _AceRange(
start.lineNumber - 1,
start.column - 1,
end.lineNumber - 1,