From e9039171792bcb563afbbab5cbc587d1252880d4 Mon Sep 17 00:00:00 2001 From: Aljaz Grilc Date: Wed, 4 Jun 2025 13:18:30 +0200 Subject: [PATCH] Add navigation buttons in popup #4 --- service.js | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/service.js b/service.js index 62cf58b..dab0959 100644 --- a/service.js +++ b/service.js @@ -354,6 +354,13 @@ class BesService { this.findNextMistake(1) } break + case 'Enter': + if (e.ctrlKey) { + e.preventDefault() + e.stopPropagation() + // TODO: What to do when we have multiple replacements? + this.acceptReplacement() + } default: break } @@ -1023,6 +1030,11 @@ class BesService { ) } + static arrowBtnNavigation(value, service) { + const direction = value === 'forward' ? 1 : value === 'back' ? -1 : 0 + service.findNextMistake(direction) + } + /** * Creates auxiliary DOM elements for text adornments. */ @@ -1130,7 +1142,7 @@ class BesService { popup.setContent(el, match, this, this.isContentEditable()) this.highlightMistake(match) }) - popup.show(source.clientX, source.clientY) + popup.show(source.clientX, source.clientY, this) } /** @@ -1189,7 +1201,7 @@ class BesService { this.highlightMistake(match) match.highlights.forEach(el => { const clientY = `${el.y + 150}` - popup.show(el.x, clientY) + popup.show(el.x, clientY, this) }) } @@ -2863,7 +2875,7 @@ class BesPopup extends HTMLElement { padding: 3px 2px; } .bes-toolbar button { - margin-right: 2px; + margin-right: 0px; } .bes-popup-title { color: #333; @@ -2904,6 +2916,9 @@ class BesPopup extends HTMLElement { width: 100%; height: 100%; } + .bes-mistake-nav{ + margin-right: 10px; + } :host{ --bes-close-icon: #485362; --hover-bg-clr: #dee3ed; @@ -2948,12 +2963,36 @@ class BesPopup extends HTMLElement {
Besana
+
+ + +
` + const prevBtn = this.shadowRoot.querySelector( + '.bes-mistake-nav .bes-close-btn[title="Prejšnja napaka"]' + ) + const nextBtn = this.shadowRoot.querySelector( + '.bes-mistake-nav .bes-close-btn[title="Naslednja napaka"]' + ) + + prevBtn.addEventListener('click', () => { + if (this.hostElService) + BesService.arrowBtnNavigation('back', this.hostElService) + }) + nextBtn.addEventListener('click', () => { + if (this.hostElService) + BesService.arrowBtnNavigation('forward', this.hostElService) + }) + this.addEventListener('mousedown', this.onMouseDown) } @@ -2963,9 +3002,9 @@ class BesPopup extends HTMLElement { * @param {Number} x X location hint * @param {Number} y Y location hint */ - show(x, y) { - console.log(x, y) + show(x, y, service) { this.style.position = 'fixed' + this.hostElService = service // Element needs some initial placement for the browser to provide this.offsetWidth and this. // offsetHeight measurements.