Skip to content

Conversation

@lukasbuenger
Copy link
Contributor

@lukasbuenger lukasbuenger commented Feb 27, 2019

Relations:

  • Issue: livingdocsIO/livingdocs-planning/issues/2472
  • Related PR's:
    • livingdocsIO/livingdocs-framework#378
    • livingdocsIO/livingdocs-editor#2646

Changelog

  • API method highlight now takes an additional optional option argument textRange {start: number, end: number, text: string }. If given, it is used to determine the span position rather than the regex matches on text.
  • Added rangy's TextRange module.

Known issues

  • Formatting a selection that includes a comment edge will remove any comment span in the editable container
  • Splitting a comment destroys the highlight.
  • Splitting a component before a comment destroys the highlight.
  • Merging a component destroys all highlights in the second component.

Pull Request Checklist

  • Tests

@lukasbuenger lukasbuenger mentioned this pull request Mar 15, 2019
1 task
@lukasbuenger
Copy link
Contributor Author

Closed for now in favor of #166

@lukasbuenger lukasbuenger force-pushed the feat-highlight-range branch from f4b3005 to 9f5ee6b Compare March 19, 2019 09:31
src/core.js Outdated
* @param {String} options.text
* @param {String} options.highlightId Added to the highlight markups in the property `data-word-id`
* @param {Object} [options.textRange] An optional range which gets used to set the markers.
* @param {Number} [options.textRange.start]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think start and end are not optional if a textRange object is passed, right? So I think we can remove the square brackets around the param name here and in the next line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


describe('highlightSupport', () => {
beforeEach(() => {
setupHighlightEnv(this, 'People Make The <br> World Go Round')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should replace all arrow functions in this file with regular functions if you use this here. Otherwise this code is quite misleading.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(We could also do this in a separate PR for all tests in editable.js)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to go with your second suggestion, as currently a lot of tests misbehave if you only just adjust the beforeEach scopings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to go with your second suggestion

That's ok

as currently a lot of tests misbehave if you only just adjust the beforeEach scopings.

This is because you have to change all methods in the same file at once, otherwise you mix scopes which does not work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did replace all of them to the point where I had now arrow functions at all anymore (at least in this spec), but still all hell broke loose. I'd rather do this with a little more focus and time.

})
})

describe('highlightSupport', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these tests never test if we actually to the right thing! You only check that the index positions are the same, we do not know that the right characters are selected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests now check for the text equivalent of the ranges. See also comment below.

*
* @param {Object} options
* @param {DOMNode} options.editableHos
* @return {Object} ranges
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not include the text in the ranges? Otherwise how do you get the text of a range?

Copy link
Contributor Author

@lukasbuenger lukasbuenger Apr 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not include the text in the ranges?

Done. Good point. Will have to adjust specs in the framework as well. JFYI

throttle: 1000,
// remove highlights after a change if the cursor is inside a highlight
removeOnCorrection: true,
removeOnCorrection: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this change?

@lukasbuenger lukasbuenger requested a review from peyerluk April 20, 2019 11:03
end: 9
}
}
const expectedHtml = this.formatHtml(`People M
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two closing spans. Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my typo. The test was still passing because of this

@lukasbuenger lukasbuenger merged commit ef1e8a6 into master Apr 24, 2019
@delete-merged-branch delete-merged-branch bot deleted the feat-highlight-range branch April 24, 2019 13:23
@livingdocs-automation
Copy link
Collaborator

🎉 This PR is included in version 1.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

livingdocs-automation pushed a commit that referenced this pull request Apr 24, 2019
Merge: 2bcc82f 8541e62
Author: Lukas Bünger <lukasbuenger@gmail.com>
Date:   Wed Apr 24 15:23:00 2019 +0200

    Merge pull request #164 from livingdocsIO/feat-highlight-range

    feat(highlighting): Can display textrange-based highlights
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

Successfully merging this pull request may close these issues.

5 participants