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

fixes issue #681 with pasteHtml incorrectly re-hydrating tabs. #684

Merged
merged 1 commit into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions formats/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Parchment from 'parchment';
class IdentAttributor extends Parchment.Attributor.Class {
add(node, value) {
if (value === '+1' || value === '-1') {
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 actually think this can and should be removed... the +1/-1 is really a function of the toolbar and is handled as such in modules/toolbar.js, with the debugger attached, this method never got hit with a value that was a string === "+1" || "-1" it was always the existing indent incremented or decremented.

Copy link
Member

Choose a reason for hiding this comment

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

The keyboard also uses this +1/-1 functionality

let indent = parseInt(this.value(node) || 0);
value = value === '+1' ? (indent + 1) : (indent - 1);
let indent = this.value(node) || 0;
value = (value === '+1' ? (indent + 1) : (indent - 1));
}
if (value === 0) {
this.remove(node);
Expand All @@ -13,6 +13,9 @@ class IdentAttributor extends Parchment.Attributor.Class {
return super.add(node, value);
}
}
value(node){
return parseInt(super.value(node));
}
}

let IndentClass = new IdentAttributor('indent', 'ql-indent', {
Expand Down
2 changes: 1 addition & 1 deletion modules/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class Toolbar extends Module {
option.selected = true;
}
} if (input.value) {
input.classList.toggle('ql-active', input.value == formats[format]); // Intentional ==
input.classList.toggle('ql-active', input.value === formats[format]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

since this change allows a white list to be specified as integers instead of strings but the value "+1" actually matters for indent toolbar buttons, it needs to be ===.

The way it was, an active button can't be clicked twice and the button is determined active if the value of the button is the same as the value of the format. An active button can't be activated again and the value for the button was being set to false before being passed through to format.

The root cause is that == will coerce a string to an integer to do a comparison, which in the case of indent means a delta with format 'indent': 1 has the same value as "+1", which is not really true for the indent "+1" button.

I think this change isn't necessary if the restriction that whitelists be strings and and Attributor.value always returns a string is in place. If we allow the whitelist to contain numbers, then the attributor with a numeric whitelist's value function needs to return a number. If value can return a number instead of string then toolbar update needs strict ===.

Copy link
Member

@jhchen jhchen May 23, 2016

Choose a reason for hiding this comment

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

I believe the general case of <button value="1"> gets broken by this === change.

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 don't think it does... but i'll test in the code pen.

} else {
input.classList.toggle('ql-active', formats[format] || false);
}
Expand Down