Skip to content

Commit

Permalink
Renamed position to begin
Browse files Browse the repository at this point in the history
  • Loading branch information
denisoed committed Jan 31, 2022
1 parent f3101ee commit b0cbaa8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ export default class OrthographyPlugin extends Plugin {
this.hints = await this.fetchData(text);
if (this.hints instanceof TypeError) {
this.popup.removeLoader();
new Notice('Server not responding');
this.toggler.removeLoading();
new Notice(
'The server is not responding. Please check your Internet connection.'
);
return;
}
if (this.hints && this.hints.alerts && this.hints.alerts.length) {
Expand Down Expand Up @@ -146,7 +149,7 @@ export default class OrthographyPlugin extends Plugin {
private onReplaceWord(event: any) {
const origWordLen = event.currentTarget.dataset.text.length;
const newWord = event.currentTarget.dataset.toreplace;
const begin = event.currentTarget.dataset.position;
const begin = event.currentTarget.dataset.begin;
const end = begin + origWordLen;
self.editor.replaceWord(
self.activeEditor,
Expand Down
10 changes: 5 additions & 5 deletions src/orthography/UIElements/UIHints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const renderHints = (card: IData, index: number): string => {
<span
data-toreplace="${item}"
data-index="${index}"
data-position="${begin}"
data-begin="${begin}"
data-text="${text}"
class="obsidian-orthography-word-to-replace obsidian-orthography-popup-replacement"
title="Click to correct your spelling">
Expand All @@ -25,7 +25,7 @@ const renderHints = (card: IData, index: number): string => {
) {
return `
<span
data-position="${begin}"
data-begin="${begin}"
data-text="${text}"
data-toreplace="${replacements[0]}"
class="obsidian-orthography-word-to-replace obsidian-orthography-popup-hightligh--red">${
Expand All @@ -41,7 +41,7 @@ const renderHints = (card: IData, index: number): string => {
<span
data-toreplace="${item}"
data-index="${index}"
data-position="${begin}"
data-begin="${begin}"
data-text="${highlightText}"
class="obsidian-orthography-word-to-replace obsidian-orthography-popup-replacement"
title="Click to correct your spelling"
Expand All @@ -58,7 +58,7 @@ const renderHints = (card: IData, index: number): string => {
<span
data-toreplace="${item}"
data-index="${index}"
data-position="${begin}"
data-begin="${begin}"
data-text="${text}"
class="obsidian-orthography-word-to-replace obsidian-orthography-popup-replacement"
title="Click to correct your spelling"
Expand All @@ -82,7 +82,7 @@ const UIHints = (alerts: IData[]): string => {
begin
} = card;
return `
<div data-position="${begin}" id="obsidian-orthography-popup-item-${index}" class="obsidian-orthography-popup-item ${impact}">
<div data-begin="${begin}" id="obsidian-orthography-popup-item-${index}" class="obsidian-orthography-popup-item ${impact}">
<div class="obsidian-orthography-popup-minicard">
<div>${highlightText || ''}</div>
${
Expand Down
4 changes: 3 additions & 1 deletion src/orthography/orthographyEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export class OrthographyEditor implements IOrthographyEditor {
{
className: O_HIGHLIGHT,
attributes: {
position: originalWord.begin
begin: originalWord.begin,
end: originalWord.end,
len: originalWord.len
}
}
);
Expand Down
20 changes: 9 additions & 11 deletions src/orthography/orthographyPopup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ export class OrthographyPopup {
e.currentTarget.classList.add(O_POPUP_ITEM_OPENED);
}

const position = e.currentTarget.dataset.position;
if (position) {
self.scrollToWord(position);
const begin = e.currentTarget.dataset.begin;
if (begin) {
self.scrollToWord(begin);
}
}

Expand Down Expand Up @@ -187,8 +187,8 @@ export class OrthographyPopup {
}

private onFocusWord(e: any) {
const p = e.currentTarget.dataset.position;
const word = document.querySelector(`[position="${p}"]`);
const begin = e.currentTarget.dataset.begin;
const word = document.querySelector(`[begin="${begin}"]`);
if (word) {
word.classList.add(O_HIGHLIGHT_FOCUSED);
}
Expand All @@ -214,21 +214,19 @@ export class OrthographyPopup {
}

private onOpenCard(event: any) {
const { value: position } = event.currentTarget.attributes.position;
const { value: begin } = event.currentTarget.attributes.begin;
const popup: any = document.querySelector(`.${O_POPUP}`);
const opened = document.querySelectorAll(`.${O_POPUP_ITEM_OPENED}`);
opened.forEach((o) => o.classList.remove(O_POPUP_ITEM_OPENED));
const selected: any = document.querySelector(
`[data-position="${position}"]`
);
const selected: any = document.querySelector(`[data-begin="${begin}"]`);
selected.classList.add(O_POPUP_ITEM_OPENED);
popup.scrollTop = selected.offsetTop;
}

private scrollToWord(position: number) {
private scrollToWord(begin: number) {
const activeEditor = self.getEditor();
const scroller = activeEditor.getScrollerElement();
scroller.scrollTop = +position - 300;
scroller.scrollTop = +begin - 300;
}

private getEditor() {
Expand Down

0 comments on commit b0cbaa8

Please sign in to comment.