Skip to content

Commit bbcd070

Browse files
committed
cleanup term.js and pages
1 parent 0c4e75b commit bbcd070

File tree

2 files changed

+5
-72
lines changed

2 files changed

+5
-72
lines changed

entry/src/main/ets/pages/Index.ets

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ class NativeProxy {
2424
this.webviewController = webviewController
2525
}
2626

27-
propUpdate(key: object, value: object): void {
28-
hilog.info(DOMAIN, 'WebTerminal', '%{public}s', 'propUpdate: ' + key + ", value: " + value);
29-
}
30-
3127
sendInput(data: string): void {
3228
hilog.info(DOMAIN, 'WebTerminal', '%{public}s', 'sendInput: ' + data);
3329
let buffer = stringToArrayBuffer(data, 'utf-8');
@@ -40,32 +36,11 @@ class NativeProxy {
4036
napi.resize(s.width, s.height)
4137
}
4238

43-
focus(): void {
44-
hilog.info(DOMAIN, 'WebTerminal', '%{public}s', 'focus')
45-
}
46-
47-
syncFocus(): void {
48-
hilog.info(DOMAIN, 'WebTerminal', '%{public}s', 'syncFocus')
49-
}
50-
51-
newScrollHeight(h: number): void {
52-
hilog.info(DOMAIN, 'WebTerminal', '%{public}s', 'newScrollHeight: ' + h)
53-
}
54-
55-
newScrollTop(h: number): void {
56-
hilog.info(DOMAIN, 'WebTerminal', '%{public}s', 'newScrollTop: ' + h)
57-
}
58-
59-
openLink(url: string): void {
60-
hilog.info(DOMAIN, 'WebTerminal', '%{public}s', 'openLink: ' + url)
61-
}
62-
6339
async load(): Promise<void> {
40+
6441
hilog.info(DOMAIN, 'WebTerminal', '%{public}s', 'load')
6542
this.webviewController.runJavaScript('exports.setFocused(true)')
6643

67-
const s: Size = await this.getSize();
68-
6944
napi.onData((a: ArrayBuffer) => {
7045
let dec = util.TextDecoder.create('utf-8', { ignoreBOM: true })
7146
let s: string = dec.decodeToString(new Uint8Array(a))
@@ -75,14 +50,14 @@ class NativeProxy {
7550
this.webviewController.runJavaScript('exports.write("' + s + '")')
7651
})
7752

53+
const s: Size = await this.getSize();
7854
napi.run(s.width, s.height)
7955
}
8056

8157
private async getSize(): Promise<Size> {
8258
const ext = await this.webviewController.runJavaScriptExt('exports.getSize()');
8359
const arr = ext.getArray();
84-
const w = arr[0] as number, h = arr[1] as number;
85-
return { width: w, height: h };
60+
return { width: arr[0] as number, height: arr[1] as number };
8661
}
8762
}
8863

@@ -111,8 +86,7 @@ struct Index {
11186
.javaScriptProxy({
11287
object: this.native,
11388
name: 'native',
114-
methodList: ['propUpdate', 'sendInput', 'resize', 'focus', 'syncFocus',
115-
'newScrollHeight', 'newScrollTop', 'openLink', 'load', 'syncFocus'],
89+
methodList: ['sendInput', 'resize', 'load'],
11690
controller: this.webviewController,
11791
asyncMethodList: [],
11892
permission: `{

entry/src/main/resources/rawfile/term.js

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,9 @@ function onTerminalReady() {
3939
term.io.push();
4040
term.reset();
4141

42-
let oldProps = {};
43-
44-
function syncProp(name, value) {
45-
if (oldProps[name] !== value) {
46-
native.propUpdate(name, value);
47-
}
48-
}
49-
5042
let decoder = new TextDecoder();
5143
exports.write = (data) => {
5244
term.io.writeUTF16(decoder.decode(lib.codec.stringToCodeUnitArray(data)));
53-
syncProp('applicationCursor', term.keyboard.applicationCursor);
5445
};
5546

5647
// hterm size updates native size
@@ -69,22 +60,14 @@ function onTerminalReady() {
6960
e.stopPropagation();
7061
}
7162
}, { capture: true });
72-
term.scrollPort_.screen_.addEventListener('mousedown', (e) => {
73-
// Taps while there is a selection should be left to the selection view
74-
if (document.getSelection().rangeCount != 0) {
75-
return;
76-
}
77-
native.focus();
78-
});
63+
7964
exports.setFocused = (focus) => {
8065
if (focus) {
8166
term.focus();
8267
} else {
8368
term.blur();
8469
}
8570
};
86-
term.scrollPort_.screen_.addEventListener('focus', (e) => native.syncFocus());
87-
8871
// Scroll to bottom wrapper
8972
exports.scrollToBottom = () => term.scrollEnd();
9073
// Set scroll position
@@ -94,30 +77,6 @@ function onTerminalReady() {
9477
lastScrollTop = term.scrollPort_.screen_.scrollTop;
9578
};
9679

97-
// Send scroll height and position to native code
98-
let lastScrollHeight, lastScrollTop;
99-
100-
function syncScroll() {
101-
const scrollHeight = parseFloat(term.scrollPort_.scrollArea_.style.height);
102-
if (scrollHeight != lastScrollHeight) {
103-
native.newScrollHeight(scrollHeight);
104-
}
105-
lastScrollHeight = scrollHeight;
106-
107-
const scrollTop = term.scrollPort_.screen_.scrollTop;
108-
if (scrollTop != lastScrollTop) {
109-
native.newScrollTop(scrollTop);
110-
}
111-
lastScrollTop = scrollTop;
112-
}
113-
114-
const realSyncScrollHeight = hterm.ScrollPort.prototype.syncScrollHeight;
115-
hterm.ScrollPort.prototype.syncScrollHeight = function () {
116-
realSyncScrollHeight.call(this);
117-
syncScroll();
118-
};
119-
term.scrollPort_.screen_.addEventListener('scroll', syncScroll);
120-
12180
exports.updateStyle = ({
12281
foregroundColor,
12382
backgroundColor,

0 commit comments

Comments
 (0)