question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How do I select mark and delete it ?

See original GitHub issue

The docs only show the example of using onKeyDown: https://docs.slatejs.org/walkthroughs/using-plugins

Now, I read the mark from database, and show mark at startup.

The flow:

  1. use external buttons(not keyCode) to add marks (I have done this, but there is a bug, if I use two different marker button to mark same selection, slate would broken ,I don’t know if it is relate to slate)

  2. save mark info to db

  3. When I meet this page again, read data from db, and rebuild marks.

  4. How do I delete marks ???

currently I have to do as below

image

select the exactly text, and click the same mark button again to delete it. the selection not show in my mark too, really not a good way. I prefer click this mark, press Delete key to delete it. But have no idea.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

5reactions
allesklarbeidircommented, Mar 17, 2018

Hey, I’ve also had this problem and it took me some time to get it working. I looked up the source code and found that removeMark is using removeMarkAtRange and value.selection as range. The problem is, like you have described, that if you just have your cursor within the mark and calling removeMark would not change anything because the value.selection is not expanded to the whole mark.

I solved the problem by going one by one to the left until there is no mark anymore in the current selection and then one by one to the right untill there is no mark anymore. Save the startPosition and endPosition in a var, select the range and call removeMark.

Here’s a snippet:

this.props.editor.change( (change) => {

        let ch = change;

        let startPos = ch.value.selection.startOffset;            
        while(ch.value.document.getMarksAtRange(ch.value.selection).some(mark => mark.type === "MARK_TYPE_TO_REMOVE")){
                 ch = ch.move(-1);
                 startPos--;
         }
            
        ch = ch.move(1);
        let endPos = startPos;

        while(ch.value.document.getMarksAtRange(ch.value.selection).some(mark => mark.type === "MARK_TYPE_TO_REMOVE")){
                ch = ch.move(1);
                endPos++;
         }

        ch.select({
            anchorOffset: startPos,
            focusOffset: endPos,
            isFocused: true,
            isBackward: false,
        })
        .removeMark({
            type: "MARK_TYPE_TO_REMOVE"
        });
            
});

But, I agree, it should be easier to do.

0reactions
schneidmastercommented, Jan 26, 2018

I’m going to go ahead and close this issue since it’s gone stale. Feel free to follow up with a jsfiddle if you’re still stuck 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Delete marks for selected parts | Tekla User Assistance
To delete the marks, press Delete on the keyboard, or right-click in the drawing and select Delete.
Read more >
how to delete more than one photo at a time in Windows 10 ...
To select more than one item at a time: Hold down the CTRL key and click on the files or folders you want...
Read more >
Deleting multiple selected images - Help Guide
Deletes the selected images. (1) Select the images to be deleted, then press on the center of the control wheel. The mark is...
Read more >
Delete or hide photos and videos on iPhone - Apple Support
Delete : Tap Select, tap or drag your finger on the screen to select the items you want to delete, then tap the...
Read more >
How Can I Bulk Select and Delete Photos? - MacMost
Instead of deleting them, mark each one. Then delete all of the marked ones, or the ones you've accumulated so far. There are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found