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

If possible, Suggested changes should omit Deleted text and only include Inserted text #194

Closed
hftf opened this issue Jun 12, 2024 · 4 comments · Fixed by #213
Closed

If possible, Suggested changes should omit Deleted text and only include Inserted text #194

hftf opened this issue Jun 12, 2024 · 4 comments · Fixed by #213
Labels
enhancement New feature or request

Comments

@hftf
Copy link

hftf commented Jun 12, 2024

Currently, both are concatenated one after the other, sometimes causing incomprehensible output.

@Mr0grog
Copy link
Owner

Mr0grog commented Jun 12, 2024

Oh, interesting! I hadn't looked at how edits in suggest changes mode show up at all. I will see what I can do. Alternatively, feel free to file a PR!

@Mr0grog
Copy link
Owner

Mr0grog commented Jun 12, 2024

Well, the bad news is that I don’t think this is going to be possible in Safari. It should be do-able in most other browsers, but it might be a little complex and take some time.

The basic setup here is that Google Docs doesn’t put anything in the rich text/HTML representation of the document that differentiates between the suggested and normal text. However, there is some info about the suggestions in the "Docs Slice" proprietary format of the data. Safari’s security restrictions prevent us from reading that data from the pasteboard (since it comes from a different domain, we only get the standardized formats and nothing proprietary/custom), but we can check it in most other browsers.

In the docs slice, we have data.resolved.dsl_suggesteddeletions and data.resolved.dsl_suggestedinsertions for deletions and insertions, respectively. Each one contains an stsl_sugg array that has sub-arrays at the indexes where the suggestions start and end in the text. Other indexes are null. The subarray has one value in it if it is the start of a suggestion and no values in it if it is the end of the suggestion.

For example, the text (where ~ marks a deletion and + an insertion):

This is a test of +suggested +changes +to+~in~ documents.
                  ^^         ^^       ^^ ^^^ ^^
                  |          |        |  |   |
                  18         28       36 |   40
                                         38

Has slice clip data like:

{
  "resolved": {
    "dsl_spacers": "This is a test of suggested changes toin documents.",
    "dsl_suggestedinsertions": {
      "sgsl_sugg": [
        [],
        null,                      // repeated nulls for indexes 1-17
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        ["suggest.36xzw8xfadwd"],  // at index 18
        null,                      // repeated nulls for indexes 19-27
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        [],                        // at index 28
        null,                      // repeated nulls for indexes 29-35
        null,
        null,
        null,
        null,
        null,
        null,
        ["suggest.mtgbiqaxvzgz"],  // at index 36
        null,
        []                         // at index 38
      ]
    },
    "dsl_suggesteddeletions": {
      "sgsl_sugg": [
        [],
        null,                      // repeated nulls for indexes 1-37
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        ["suggest.mtgbiqaxvzgz"],  // at index 38
        null,
        []                         // at index 40
      ]
    }
    // ...other properties...
  }
}

The values are in the form: suggest.<id> where the id is the same for the insertion and deletion entry of something that is a replacement.

@Mr0grog Mr0grog added the enhancement New feature or request label Jun 12, 2024
@Mr0grog
Copy link
Owner

Mr0grog commented Jun 12, 2024

@hftf in the mean time (or if you are in Safari), I think the best you can really do is switch the doc to “viewing” mode (instead of “editing” or “suggesting”) and copy from there. Unfortunately that hides the suggestions, rather than taking/using them.

@hftf
Copy link
Author

hftf commented Jun 13, 2024

Thank you for investigating! I don't think I have the bandwidth to learn the codebase and make a PR at the moment, so will await progress if there is any!

Mr0grog added a commit that referenced this issue Aug 14, 2024
Mr0grog added a commit that referenced this issue Aug 14, 2024
This adds handling for suggested changes in a Google Doc. Before, if there were suggestions in the text, we'd show them in a totally undifferentiated way right next to the original text, which could make things appear totally garbled.

This also adds a settings UI for choosing how to convert the suggestions: you can show them marked up as insertions and deletions in the markdown, accept them and render them as normal text, or reject them and render the markdown as if they weren’t there (the default). Settings are saved in localStorage so it’s consistent across uses and page loads.

I've been meaning to add settings like this for a while, and a followup change will add the ability to choose how heading IDs are handled. This also has infrastructure we can re-use in the future for linking to bookmarks in the text.

Fixes #194.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants