-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Enable cross-block mouse selection #737
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
84689b5
Do not start multi-block selection on UI elements (#662)
gohabereg d2cb37f
Add link to issue
gohabereg 7d1ce59
Merge branch 'release/2.12' of https://github.com/codex-team/codex.ed…
a750894
Fix loss of pointer (#666)
gohabereg 4073724
Update shortcuts module (#685)
khaydarov a146c2e
Remove margin top for inline-link icon (#690)
talyguryn f0d9548
Pull fresh tools
talyguryn d5bc6fa
Remove changelog contents from readme (#700)
kabachook 57b5a09
Merge branch 'master' of https://github.com/codex-team/codex.editor i…
gohabereg f554945
#665 API to open and close inline-toolbar (#711)
tanmayv 5f71c6f
Allow holderId work with ref on dom element (#710)
dimensi ca214b5
Enable cross-block mouse selection
gohabereg ed9751a
wip
gohabereg 12a7eb2
Merge branch 'release/2.15' of https://github.com/codex-team/codex.ed…
gohabereg 7f118e1
Mouse selection works
gohabereg 17ab2f7
Comments
gohabereg 618aa5a
Fix CBS in safari
neSpecc db0bde7
remove click conflict flag
neSpecc 6d8f3dc
Update mouseSelection.ts
neSpecc 939f2e8
Fix due comments
gohabereg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import Module from '../__module'; | ||
import Block from '../block'; | ||
import SelectionUtils from '../selection'; | ||
|
||
export default class MouseSelection extends Module { | ||
/** | ||
* Block where selection is started | ||
*/ | ||
private firstSelectedBlock: Block; | ||
|
||
/** | ||
* Sets up listeners | ||
* | ||
* @param {MouseEvent} event - mouse down event | ||
*/ | ||
public watchSelection(event: MouseEvent): void { | ||
const {BlockManager, UI, Listeners} = this.Editor; | ||
|
||
this.firstSelectedBlock = BlockManager.getBlock(event.target as HTMLElement); | ||
|
||
Listeners.on(UI.nodes.redactor, 'mouseover', (mouseOverEvent) => { | ||
this.onMouseOver(mouseOverEvent as MouseEvent); | ||
}); | ||
|
||
Listeners.on(UI.nodes.redactor, 'mouseup', () => { | ||
this.onMouseUp(); | ||
}); | ||
} | ||
|
||
/** | ||
* Mouse up event handler. | ||
* Removes the listeners because selection is finished | ||
*/ | ||
private onMouseUp(): void { | ||
const {Listeners, UI} = this.Editor; | ||
|
||
Listeners.off(UI.nodes.redactor, 'mouseover'); | ||
Listeners.off(UI.nodes.redactor, 'mouseup'); | ||
} | ||
|
||
/** | ||
* Mouse over event handler | ||
* Gets target and related blocks and change selected state for blocks in between | ||
* | ||
* @param {MouseEvent} event | ||
*/ | ||
private onMouseOver(event: MouseEvent): void { | ||
const {BlockManager} = this.Editor; | ||
const relatedBlock = BlockManager.getBlockByChildNode(event.relatedTarget as Node); | ||
const targetBlock = BlockManager.getBlockByChildNode(event.target as Node); | ||
|
||
if (!relatedBlock || !targetBlock) { | ||
return; | ||
} | ||
|
||
if (targetBlock === relatedBlock) { | ||
return; | ||
} | ||
|
||
if (relatedBlock === this.firstSelectedBlock) { | ||
SelectionUtils.get().removeAllRanges(); | ||
|
||
relatedBlock.selected = true; | ||
targetBlock.selected = true; | ||
return; | ||
} | ||
|
||
if (targetBlock === this.firstSelectedBlock) { | ||
relatedBlock.selected = false; | ||
targetBlock.selected = false; | ||
return; | ||
} | ||
|
||
this.toggleBlocksSelection(relatedBlock, targetBlock); | ||
} | ||
|
||
/** | ||
* Change blocks selection state between passed two blocks. | ||
* | ||
* @param {Block} firstBlock | ||
* @param {Block} lastBlock | ||
*/ | ||
private toggleBlocksSelection(firstBlock: Block, lastBlock: Block): void { | ||
const {BlockManager} = this.Editor; | ||
const fIndex = BlockManager.blocks.indexOf(firstBlock); | ||
const lIndex = BlockManager.blocks.indexOf(lastBlock); | ||
|
||
/** | ||
* If first and last block have the different selection state | ||
* it means we should't toggle selection of the first selected block. | ||
* In the other case we shouldn't toggle the last selected block. | ||
*/ | ||
const shouldntSelectFirstBlock = firstBlock.selected !== lastBlock.selected; | ||
|
||
for (let i = Math.min(fIndex, lIndex); i <= Math.max(fIndex, lIndex); i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. и почему бы тут цикл не начинать с Math.min(fIndex, lIndex) + 1 до i < Math.max(fIndex, lIndex) раз ты в условии пропускаешь первый и последний Если я что-то не понимаю, добавь в комментах, плиз |
||
const block = BlockManager.blocks[i]; | ||
|
||
if ( | ||
block !== this.firstSelectedBlock && | ||
block !== (shouldntSelectFirstBlock ? firstBlock : lastBlock) | ||
) { | ||
BlockManager.blocks[i].selected = !BlockManager.blocks[i].selected; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вообще не понимаю что это за условие. Первый и последний блок ведь никак не связаны. Расскажи, плиз, что это за кейс