From 802aa366633761eb5ef5a47d2bf38889a7eae5c2 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sat, 2 Feb 2019 17:34:01 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B4=20SearchPage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/Reader.vue | 2 +- .../Reader/SearchPage/SearchPage.vue | 46 +++++++++++++------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/client/components/Reader/Reader.vue b/client/components/Reader/Reader.vue index dbff37ee..d73cba8c 100644 --- a/client/components/Reader/Reader.vue +++ b/client/components/Reader/Reader.vue @@ -59,7 +59,7 @@ - + diff --git a/client/components/Reader/SearchPage/SearchPage.vue b/client/components/Reader/SearchPage/SearchPage.vue index 2d3e84f1..a5d9e89b 100644 --- a/client/components/Reader/SearchPage/SearchPage.vue +++ b/client/components/Reader/SearchPage/SearchPage.vue @@ -16,8 +16,8 @@
{{ foundText }}
- - + + @@ -43,7 +43,7 @@ export default @Component({ }, foundText: function(newValue) { - this.$refs.input.style.paddingRight = newValue.length*12 + 'px'; + this.$refs.input.style.paddingRight = (10 + newValue.length*12) + 'px'; }, }, }) @@ -87,7 +87,7 @@ class SearchPage extends Vue { prevPerc = perc; } } - this.text = text; + this.text = text.toLowerCase(); this.initStep = false; this.header = 'Найти'; @@ -98,26 +98,46 @@ class SearchPage extends Vue { get foundText() { if (this.foundList.length && this.foundCur >= 0) - return `${this.foundCur}/${this.foundList.length}`; + return `${this.foundCur + 1}/${this.foundList.length}`; else return ''; } find() { let foundList = []; - let i = 0; - while (i < this.text.length) { - i++; + if (this.needle) { + const needle = this.needle.toLowerCase(); + let i = 0; + while (i < this.text.length) { + const found = this.text.indexOf(needle, i); + if (found >= 0) + foundList.push(found); + i = (found >= 0 ? found + 1 : this.text.length); + } } this.foundList = foundList; + this.foundCur = -1; + this.showNext(); } - findNext() { - console.log('1'); + showNext() { + const next = this.foundCur + 1; + if (next < this.foundList.length) + this.foundCur = next; + else + this.foundCur = (this.foundList.length ? 0 : -1); + this.$emit('book-pos-changed', {bookPos: this.foundList[this.foundCur]}); + this.$refs.input.focus(); } - findPrev() { - console.log('2'); + showPrev() { + const prev = this.foundCur - 1; + if (prev >= 0) + this.foundCur = prev; + else + this.foundCur = this.foundList.length - 1; + this.$emit('book-pos-changed', {bookPos: this.foundList[this.foundCur]}); + this.$refs.input.focus(); } close() { @@ -128,7 +148,7 @@ class SearchPage extends Vue { keyHook(event) { //недостатки сторонних ui if (document.activeElement === this.$refs.input && event.type == 'keydown' && event.key == 'Enter') { - this.find(); + this.showNext(); } if (event.type == 'keydown' && (event.code == 'Escape')) {