Добавил реакцию на PageUp-PageDown, поправки багов

This commit is contained in:
Book Pauk
2019-01-16 04:30:51 +07:00
parent 2a354b1c08
commit 2faa584a01
2 changed files with 45 additions and 8 deletions

View File

@@ -24,10 +24,11 @@ export default @Component({
},
})
class TextPage extends Vue {
meta = null;
lastBook = null;
bookPos = 0;
//убрать
meta = null;
items = null;
created() {
@@ -44,6 +45,10 @@ class TextPage extends Vue {
this.fb2 = null;
this.parsed = null;
this.linesUp = null;
this.linesDown = null;
this.pageLineCount = 0;
this.drawPage();//пока не загрузили, очистим канвас
if (this.lastBook) {
@@ -64,6 +69,8 @@ class TextPage extends Vue {
this.fb2.bookTitle
]).join(' '));
this.pageLineCount = 30;
const parsed = this.book.parsed;
parsed.p = 30;//px, отступ параграфа
parsed.w = 300;//px, ширина страницы
@@ -89,11 +96,13 @@ class TextPage extends Vue {
if (!this.book)
return;
const lines = this.parsed.getLines(this.bookPos, 30);
const lines = this.parsed.getLines(this.bookPos, this.pageLineCount + 1);
let newItems = [];
for (const line of lines) {
//console.log(line);
let len = lines.length;
len = (len > this.pageLineCount ? len = this.pageLineCount : len);
for (let i = 0; i < len; i++) {
const line = lines[i];
/* line:
{
begin: Number,
@@ -111,9 +120,39 @@ class TextPage extends Vue {
newItems.push(item);
}
this.items = newItems;
this.linesUp = this.parsed.getLines(this.bookPos, -(this.pageLineCount + 1));
this.linesDown = lines;
}
pageDown() {
let i = this.pageLineCount;
i--;
if (this.linesDown && this.linesDown.length > i) {
this.bookPos = this.linesDown[i].begin;
}
}
pageUp() {
let i = this.pageLineCount;
i--;
i = (i > this.linesUp.length - 1 ? this.linesUp.length - 1 : i);
if (this.linesUp && this.linesUp.length > i) {
this.bookPos = this.linesUp[i].begin;
}
}
keyHook(event) {
if (event.type == 'keydown') {
switch (event.key) {
case 'PageDown':
this.pageDown();
break;
case 'PageUp':
this.pageUp();
break;
}
}
}
}
//-----------------------------------------------------------------------------

View File

@@ -13,8 +13,6 @@ export default class BookParser {
this.measureText = (text, style) => {// eslint-disable-line no-unused-vars
return text.length*10;
};
// stuff
}
async parse(data, callback) {
@@ -349,9 +347,9 @@ export default class BookParser {
result.push(parsed.lines[i]);
i--;
if (i > 0) {
if (i < 0) {
paraIndex--;
if (paraIndex >= this.para.length)
if (paraIndex >= 0)
parsed = this.parsePara(paraIndex);
else
return result;