Skip to content

Commit

Permalink
Merge pull request #611 from ONLYOFFICE/bugfix/fixed-hotkeys-selectio…
Browse files Browse the repository at this point in the history
…n-with-arrows

Web: Files: Hotkeys: fixed arrows selection
  • Loading branch information
TatianaLopaeva authored Apr 8, 2022
2 parents e0338c0 + b2fa788 commit af86179
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions products/ASC.Files/Client/src/store/HotkeyStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,31 @@ class HotkeyStore {
};

selectBottom = () => {
const { viewAs, hotkeyCaret } = this.filesStore;
const { viewAs, hotkeyCaret, selection } = this.filesStore;

if (!hotkeyCaret) return this.selectFirstFile();
if (!hotkeyCaret && !selection.length) return this.selectFirstFile();
else if (viewAs === "tile")
this.setSelectionWithCaret([this.nextForTileDown]);
else if (this.nextFile) this.setSelectionWithCaret([this.nextFile]);
};

selectUpper = () => {
const { hotkeyCaret, viewAs } = this.filesStore;
const { hotkeyCaret, viewAs, selection } = this.filesStore;

if (!hotkeyCaret) return this.selectFirstFile();
if (!hotkeyCaret && !selection.length) return this.selectFirstFile();
else if (viewAs === "tile")
this.setSelectionWithCaret([this.prevForTileUp]);
else if (this.prevFile) this.setSelectionWithCaret([this.prevFile]);
};

selectLeft = () => {
const { hotkeyCaret, filesList, setHotkeyCaretStart } = this.filesStore;
if (!hotkeyCaret) {
const {
hotkeyCaret,
filesList,
setHotkeyCaretStart,
selection,
} = this.filesStore;
if (!hotkeyCaret && !selection.length) {
this.selectFirstFile();

setHotkeyCaretStart(filesList[0]);
Expand All @@ -158,9 +163,14 @@ class HotkeyStore {
};

selectRight = () => {
const { hotkeyCaret, filesList, setHotkeyCaretStart } = this.filesStore;
const {
hotkeyCaret,
filesList,
setHotkeyCaretStart,
selection,
} = this.filesStore;

if (!hotkeyCaret) {
if (!hotkeyCaret && !selection.length) {
this.selectFirstFile();
setHotkeyCaretStart(filesList[0]);
} else if (this.nextFile) {
Expand All @@ -183,7 +193,7 @@ class HotkeyStore {
if (!hotkeyCaretStart) {
setHotkeyCaretStart(hotkeyCaret);
}
if (!hotkeyCaret) return this.selectFirstFile();
if (!hotkeyCaret && !selection.length) return this.selectFirstFile();

if (viewAs === "tile") {
if (this.nextForTileDown.id === hotkeyCaret.id) return;
Expand Down Expand Up @@ -218,7 +228,7 @@ class HotkeyStore {
if (!hotkeyCaretStart) {
setHotkeyCaretStart(hotkeyCaret);
}
if (!hotkeyCaret) this.selectFirstFile();
if (!hotkeyCaret && !selection.length) this.selectFirstFile();

if (viewAs === "tile") {
if (this.prevForTileUp.id === hotkeyCaret.id) return;
Expand Down Expand Up @@ -251,7 +261,7 @@ class HotkeyStore {
filesList,
} = this.filesStore;

if (!hotkeyCaret) return this.selectFirstFile();
if (!hotkeyCaret && !selection.length) return this.selectFirstFile();

const nextFile = this.nextFile;
if (!nextFile) return;
Expand Down Expand Up @@ -309,7 +319,7 @@ class HotkeyStore {
hotkeyCaretStart,
} = this.filesStore;

if (!hotkeyCaret) return this.selectFirstFile();
if (!hotkeyCaret && !selection.length) return this.selectFirstFile();

const prevFile = this.prevFile;
if (!prevFile) return;
Expand Down Expand Up @@ -461,8 +471,9 @@ class HotkeyStore {
}

get caretIndex() {
const { filesList, hotkeyCaret } = this.filesStore;
const caretIndex = filesList.findIndex((f) => f.id === hotkeyCaret.id);
const { filesList, hotkeyCaret, selection } = this.filesStore;
const id = selection.length ? selection[0].id : hotkeyCaret?.id;
const caretIndex = filesList.findIndex((f) => f.id === id);

if (caretIndex !== -1) return caretIndex;
else return null;
Expand Down

0 comments on commit af86179

Please sign in to comment.