Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Update color picker when user makes edits in host editor #2147

Merged
merged 9 commits into from
Nov 20, 2012

Conversation

njx
Copy link
Contributor

@njx njx commented Nov 18, 2012

In addition to that behavior change, I also factored out logic for getting the current host editor range associated with the inline editor. I also tweaked that logic to make it a little more robust to host edits--if the end bookmark goes stale, instead of just assuming that the relevant range still corresponds to the original color length, we first re-check the color regex to try to determine the end.

Note that this is currently independent of #2142. We might want to reuse the logic from that pull request that avoids synchronizing when the text input field contains an invalid color value, and apply that to changes from the host editor as well. However, this pull could be reviewed independently of that, and we could merge the implementations later; the change would be to make handleHostEditorChange() call that factored-out logic instead of directly calling commitColor().

@ghost ghost assigned peterflynn Nov 19, 2012
@njx
Copy link
Contributor Author

njx commented Nov 19, 2012

Assigning to @peterflynn

@njx
Copy link
Contributor Author

njx commented Nov 20, 2012

OK, this should be ready for review. Note that in the scenario in #2140, we now collapse the editor. I had originally made it so that we would keep the editor open on the chance that the user might make the color valid again (and correctly update the range in that case), but since we can't really tell whether the user is going to do that in the future, it seems safer to just collapse the editor immediately. We could try to make some smarter UI for this in the future.

@@ -38,6 +38,9 @@ define(function (require, exports, module) {
this.startBookmark = startBookmark;
this.endBookmark = endBookmark;
this.setColor = this.setColor.bind(this);
this.handleHostDocumentChange = this.handleHostDocumentChange.bind(this);
this.isOwnChange = false;
this.isHostChange = false;
Copy link
Member

Choose a reason for hiding this comment

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

I know we don't have an official style policy for this, but I like to see the instance properties documented somewhere. In some of our classes we use dummy prototype copies (assigned null) to hang JSDocs off -- that's one option. (Ditto for the existing color, startBookmark & endBookmark if it's not too much trouble).

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 broke them out, so we can add the JSDocs as part of the JSDoc task.

@njx
Copy link
Contributor Author

njx commented Nov 20, 2012

Fixes pushed, ready for re-review.

result.onAdded();
inline = result;
});
waitsForDone(editorPromise, "open color editor", 500);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: the timeout arg is optional in waitsForDone(). Probably no reason not to use the default value here.

@peterflynn
Copy link
Member

Done reviewing.

@njx
Copy link
Contributor Author

njx commented Nov 20, 2012

Updates pushed.

});
});

it("should not update the end bookmark to a shorter valid match if the bookmark still exists color becomes invalid", function () {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: "if the bookmark still exists and color becomes invalid"

(can fix this in a later pull request's commit if you want)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, will fix when I finish up the unit tests.

@peterflynn
Copy link
Member

Cool, looks good then

peterflynn added a commit that referenced this pull request Nov 20, 2012
Update color picker when user makes edits in host editor. Track color's text range more robustly. Add some initial unit tests.
@peterflynn peterflynn merged commit 681808f into master Nov 20, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants