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

How to access text contents from Delta #43

Closed
yarnball opened this issue May 5, 2019 · 1 comment
Closed

How to access text contents from Delta #43

yarnball opened this issue May 5, 2019 · 1 comment

Comments

@yarnball
Copy link

yarnball commented May 5, 2019

Hi,

Very nice work on this one.

I'm working on a diff, that can show when deltas are changed/removed.

The tricky bit is- for delta's which are "deleted", I want to delete the text, but first get the contents of the delta that is deleted.

I've tried the "getText()" (quill) but it does not get the right text at all- I will pass it something like quill.getText(10,11) and it will return a much longer string that just what was deleted.

How can this be achieved?

export const getDiff = (ops, oldOps, quill) => {
  return ops.map((op,inx)=>{
    if(op.insert){
      return {...op, attributes:{attributes:{  
        background: "green",
      }}
    }
    else if(op.delete){
      const startKeep = ops[inx-1].retain
      const deletedText = quill.getText(startKeep, startKeep + op.delete)
      return op
    }
    else{
      return op
    }
  })
}
@yarnball yarnball changed the title How to access contents on Delete How to access text contents from Delta May 6, 2019
@jhchen
Copy link
Member

jhchen commented May 6, 2019

The delta itself does not contain the contents of deleted operations. You'll have to find a way to get the contents before the delete happened and reconcile. If you are using Quill, it supplies the old contents in text-change.

@jhchen jhchen closed this as completed May 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants