mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Change the selection behavior to the default behavior
There are two behaviors being changed:
1. When user click on the notes
a. Shift - It will select the notes among the first and the last note
b. Ctrl - it will only select the selected note
2. When user uses the arrow keys
a. Shift - it will extends the selection from the last selected note
b. Ctrl - Nothing will happens
This commit is contained in:
@@ -84,7 +84,9 @@ class NoteList extends React.Component {
|
|||||||
|
|
||||||
// TODO: not Selected noteKeys but SelectedNote(for reusing)
|
// TODO: not Selected noteKeys but SelectedNote(for reusing)
|
||||||
this.state = {
|
this.state = {
|
||||||
|
ctrlKeyDown: false,
|
||||||
shiftKeyDown: false,
|
shiftKeyDown: false,
|
||||||
|
firstShiftSelectedNoteIndex: -1,
|
||||||
selectedNoteKeys: []
|
selectedNoteKeys: []
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +269,7 @@ class NoteList extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleNoteListKeyDown (e) {
|
handleNoteListKeyDown (e) {
|
||||||
if (e.metaKey || e.ctrlKey) return true
|
if (e.metaKey) return true
|
||||||
|
|
||||||
// A key
|
// A key
|
||||||
if (e.keyCode === 65 && !e.shiftKey) {
|
if (e.keyCode === 65 && !e.shiftKey) {
|
||||||
@@ -307,6 +309,8 @@ class NoteList extends React.Component {
|
|||||||
|
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
this.setState({ shiftKeyDown: true })
|
this.setState({ shiftKeyDown: true })
|
||||||
|
} else if (e.ctrlKey) {
|
||||||
|
this.setState({ ctrlKeyDown: true })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,6 +318,10 @@ class NoteList extends React.Component {
|
|||||||
if (!e.shiftKey) {
|
if (!e.shiftKey) {
|
||||||
this.setState({ shiftKeyDown: false })
|
this.setState({ shiftKeyDown: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!e.ctrlKey) {
|
||||||
|
this.setState({ ctrlKeyDown: false })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getNotes () {
|
getNotes () {
|
||||||
@@ -390,25 +398,51 @@ class NoteList extends React.Component {
|
|||||||
return pinnedNotes.concat(unpinnedNotes)
|
return pinnedNotes.concat(unpinnedNotes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNoteIndexByKey (noteKey) {
|
||||||
|
return this.notes.findIndex((note) => {
|
||||||
|
if (!note) return -1
|
||||||
|
|
||||||
|
return note.key === noteKey
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
handleNoteClick (e, uniqueKey) {
|
handleNoteClick (e, uniqueKey) {
|
||||||
const { router } = this.context
|
const { router } = this.context
|
||||||
const { location } = this.props
|
const { location } = this.props
|
||||||
let { selectedNoteKeys } = this.state
|
let { selectedNoteKeys } = this.state
|
||||||
const { shiftKeyDown } = this.state
|
const { ctrlKeyDown, shiftKeyDown } = this.state
|
||||||
|
let firstShiftSelectedNoteIndex = -1
|
||||||
|
|
||||||
if (shiftKeyDown && selectedNoteKeys.includes(uniqueKey)) {
|
if (ctrlKeyDown && selectedNoteKeys.includes(uniqueKey)) {
|
||||||
const newSelectedNoteKeys = selectedNoteKeys.filter((noteKey) => noteKey !== uniqueKey)
|
const newSelectedNoteKeys = selectedNoteKeys.filter((noteKey) => noteKey !== uniqueKey)
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedNoteKeys: newSelectedNoteKeys
|
selectedNoteKeys: newSelectedNoteKeys
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!shiftKeyDown) {
|
if (!ctrlKeyDown && !shiftKeyDown) {
|
||||||
selectedNoteKeys = []
|
selectedNoteKeys = []
|
||||||
}
|
}
|
||||||
selectedNoteKeys.push(uniqueKey)
|
selectedNoteKeys.push(uniqueKey)
|
||||||
|
|
||||||
|
if (shiftKeyDown && selectedNoteKeys.length > 0) {
|
||||||
|
const firstSelectedNoteIndex =
|
||||||
|
Math.max(this.getNoteIndexByKey(selectedNoteKeys[0]),
|
||||||
|
this.state.firstShiftSelectedNoteIndex)
|
||||||
|
const lastSelectedNoteIndex = this.getNoteIndexByKey(uniqueKey)
|
||||||
|
const startIndex = Math.min(firstSelectedNoteIndex, lastSelectedNoteIndex)
|
||||||
|
const endIndex = Math.max(firstSelectedNoteIndex, lastSelectedNoteIndex)
|
||||||
|
selectedNoteKeys = []
|
||||||
|
for (let i = startIndex; i <= endIndex; i++) {
|
||||||
|
selectedNoteKeys.push(this.notes[i].key)
|
||||||
|
}
|
||||||
|
|
||||||
|
firstShiftSelectedNoteIndex = firstSelectedNoteIndex
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
selectedNoteKeys
|
selectedNoteKeys,
|
||||||
|
firstShiftSelectedNoteIndex
|
||||||
})
|
})
|
||||||
|
|
||||||
router.push({
|
router.push({
|
||||||
|
|||||||
Reference in New Issue
Block a user