Skip to content

Commit 01cae52

Browse files
authored
Merge pull request #2 from jwlilly/Find-in-page
Find in page
2 parents ffa16d8 + 6c78211 commit 01cae52

8 files changed

Lines changed: 94 additions & 8 deletions

File tree

app.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ ipcMain.on('forwardPorts', (event, arg) => {
102102
ipcMain.on('restartServer', (event, arg) => {
103103
restartServer();
104104
});
105+
ipcMain.on('findInPage', (event, arg) => {
106+
findInPage(arg[0]);
107+
});
108+
ipcMain.on('stopFindInPage', (event, arg) => {
109+
stopFindInPage();
110+
});
105111
ipcMain.on('setNotImportant', (event, arg) => {
106112
myItem = Menu.getApplicationMenu().getMenuItemById('not-important-views');
107113
myItem.checked = arg;
@@ -258,3 +264,18 @@ function startAccessibilityService(runningServices){
258264
mainWindow.webContents.send('reconnect', {'data': ""});
259265
}, 5000);
260266
}
267+
268+
function findInPage(text) {
269+
let options = {
270+
forward: true,
271+
findNext: true,
272+
matchCase: false,
273+
wordStart: false,
274+
medialCapitalAsWordStart: false
275+
}
276+
mainWindow.webContents.findInPage(text, options)
277+
}
278+
279+
function stopFindInPage() {
280+
mainWindow.webContents.stopFindInPage('clearSelection');
281+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "android-accessibility-inspector",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"main": "app.js",
55
"scripts": {
66
"ng": "ng",
@@ -65,7 +65,7 @@
6565
"@types/jasmine": "~3.8.0",
6666
"@types/jquery": "^3.5.13",
6767
"@types/node": "14.14.33",
68-
"electron": "13.6.6",
68+
"electron": "^27",
6969
"electron-builder": "^22.14.13",
7070
"electron-packager": "^16",
7171
"jasmine-core": "~3.8.0",

src/app/app.component.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div (window:resize)="onResize($event)">
1+
<div (window:resize)="onResize($event)" (keyup.escape)="stopFindInPage()">
22
<div>
33
<div *ngIf="!connected" class="alert alert-warning alert-sticky">
44
<div class="row">
@@ -27,8 +27,11 @@
2727
</div>
2828
</div>
2929
<div class="col-md">
30+
<div class="bg-white sticky-top border-bottom">
31+
<find-in-page (parentStopFindInPage)="stopFindInPage()" (parentFindInPage)="findInPage($event)"></find-in-page>
32+
</div>
3033
<div class="m-1">
31-
<ul class="list-group dark-border" *ngIf="jsonData.children">
34+
<ul class="mt-4 list-group dark-border" *ngIf="jsonData.children">
3235
<ng-template #recursiveList let-list>
3336
<li class="list-group-item dark-border" *ngFor="let node of list" [ngClass]="{'web-view' : node.role.includes('WebView'), 'system-focus' : (node.properties && node.properties.includes('focused'))}">
3437
<button id="{{ node.id }}" aria-pressed="false" class="btn btn-focus remove-btn-border" (click)="nodeClicked($event,node)">

src/app/app.component.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ElectronService } from 'ngx-electron';
55
import { BoundingBox } from './BoundingBox';
66
import {webSocket, WebSocketSubject} from 'rxjs/webSocket';
77
import { ToastrService } from 'ngx-toastr';
8+
import { FindInPage } from './components/FindInPage';
89
@Component({
910
selector: 'app-root',
1011
templateUrl: './app.component.html',
@@ -669,4 +670,13 @@ export class AppComponent implements OnInit, OnDestroy{
669670
this.webSocket.next(this.importantJson);
670671
}
671672
}
673+
674+
findInPage(event: any) {
675+
let text = event.findText as string;
676+
this._electronService.ipcRenderer.send("findInPage", [text]);
677+
}
678+
679+
stopFindInPage() {
680+
this._electronService.ipcRenderer.send("stopFindInPage");
681+
}
672682
}

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import { ObjectValuesPipe } from './json.pipe';
1010
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
1111
import { ToastrModule } from 'ngx-toastr';
1212
import { VarDirective } from './ng-var.directive';
13+
import { FindInPage } from './components/FindInPage';
1314

1415
@NgModule({
1516
declarations: [
1617
AppComponent,
1718
ObjectValuesPipe,
18-
VarDirective
19+
VarDirective,
20+
FindInPage
1921
],
2022
imports: [
2123
BrowserModule,

src/app/components/FindInPage.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="p-2 row g-3 align-items-center mb-3 search-width" id="searchPannel">
2+
<div class="col-auto">
3+
<label for="enter">Find Text</label>
4+
</div>
5+
<div class="col-auto">
6+
<input #findInput (keyup.enter)="findInPage($event)" class="form-control" id="enter" type="text">
7+
</div>
8+
<div class="col-auto">
9+
<button class="btn btn-primary me-2" #findButton id="search" (click)="findInPage($event)">Find</button>
10+
<button class="btn btn-primary" (click)="stopFindInPage()" id="clearSearch">Clear</button>
11+
</div>
12+
</div>

src/app/components/FindInPage.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Component, Output, EventEmitter, ViewChild, ElementRef} from '@angular/core';
2+
3+
@Component({
4+
selector: 'find-in-page',
5+
templateUrl: './FindInPage.html'
6+
})
7+
8+
export class FindInPage
9+
{
10+
@Output("parentFindInPage") parentFindInPage: EventEmitter<any> = new EventEmitter();
11+
@Output("parentStopFindInPage") parentStopFindInPage: EventEmitter<any> = new EventEmitter();
12+
@ViewChild('findInput') findInput:ElementRef | undefined;
13+
@ViewChild('findButton') findButton:ElementRef | undefined;
14+
15+
findInPage(event: Event) {
16+
if(this.findInput instanceof ElementRef) {
17+
let find = this.findInput as ElementRef;
18+
if(find.nativeElement.value && find.nativeElement.value.length > 0) {
19+
this.parentFindInPage.emit({findText: find.nativeElement.value});
20+
}
21+
}
22+
setTimeout(() => {
23+
this.findButton?.nativeElement.focus();
24+
}, 1);
25+
}
26+
27+
stopFindInPage() {
28+
this.parentStopFindInPage.emit();
29+
if(this.findInput instanceof ElementRef) {
30+
let find = this.findInput as ElementRef;
31+
find.nativeElement.value = "";
32+
}
33+
}
34+
}

src/styles.css

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
position:fixed;
2929
top:0;
3030
right:5px;
31-
z-index:100;
31+
z-index:2000;
3232
}
3333

3434
.dark-border {
@@ -61,12 +61,16 @@ span.system-focus-btn {
6161
display: none;
6262
}
6363

64+
.search-width {
65+
max-width: calc(100% - 70px);
66+
}
67+
6468
li.web-view span.web-view-btn {
6569
display:inline-block;
6670
margin-left: 4px;
6771
}
6872

69-
li.system-focus span.system-focus-btn {
73+
li.system-focus > button > div > span > span.system-focus-btn {
7074
display:inline-block;
7175
margin-left: 4px;
7276
}
@@ -101,7 +105,7 @@ li.web-view span.native-view-btn {
101105
.alert-sticky {
102106
position: fixed;
103107
width: 100%;
104-
z-index: 2000;
108+
z-index: 2001;
105109
}
106110
@keyframes spinner {
107111
to {transform: rotate(360deg);}

0 commit comments

Comments
 (0)