Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web: Files: Hotkeys: fixed arrows selection #611

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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