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

Removes forceLineBreaks as it is super buggy #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
69 changes: 3 additions & 66 deletions views/wysiwyg_editor_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,6 @@ SC.WYSIWYGEditorView = SC.View.extend({
*/
lineHeight: 25,

/**
This property controls the type of markup generated by the editor. By default, paragraphs are
wrapped in <p> elements. If you set this property to true, the editor will use line-break
elements (<br>) to separate paragraphs instead.

Line-breaks mode is *experimental*, and does not currently work well a number of toolbar
commands, including the "style" commands (p, h1, etc), and the text-align commands. Contributions
are greatly appreciated; see https://github.com/sproutcore/rich-text-editor/issues/16 for the
full discussion.

@type Boolean
@default false
*/
forceLineBreaks: false,

/**
Set to true to paste the content of the clipboard as plain text.

Expand Down Expand Up @@ -873,64 +858,16 @@ SC.WYSIWYGEditorView = SC.View.extend({
return ret;
},

/** @private TODO: We do a lot of munging here. Might not catch everything (e.g. paste-from-menu). */
/** @private */
keyUp: function (evt) {
var inner = this.$inner,
contents = inner.contents(),
first = contents[0],
last = contents[contents.length - 1],
forceLineBreaks = this.get('forceLineBreaks');
// If the first content is a text node, or a line break (and we're not forcing <br> mode), let's wrap it up.
if (!forceLineBreaks && first && (first.nodeType === 3 /* TEXT NODE */ || first.nodeName === "BR")) {
document.execCommand('formatBlock', false, 'p');
}
else if (!forceLineBreaks && last && (last.nodeType === 3 /* TEXT NODE */ || last.nodeName === "BR")) {
document.execCommand('formatBlock', false, 'p');
}
// In Webkit, we need to make sure that the very last <br> element, which is removed when we type above it,
// is added back in or the user will have to hit enter twice.
else if (SC.browser.isWebkit && forceLineBreaks && last && last.nodeName !== "BR") {
inner.append('<br>');
}
this.notifyDomValueChange();
this.updateState();
return YES;
},

/** @private Inserts <br> if forceLineBreaks is true. Otherwise allows default. */
/** @private */
insertNewline: function (evt) {
// If we're forcing line breaks, insert a line break.
if (this.get('forceLineBreaks')) {
// If we're empty, we need to jump-start things with a double line-break.
if (!this.$inner.html()) {
this.insertHtmlAtCaret('<br><br>');
}
// Otherwise just a single one.
else {
this.insertHtmlAtCaret('<br>');
}
}
// If we're empty, we're at our most vulnerable to unwanted browser defaults sneaking through.
else if (!this.$inner.html()) {
// If we're Webkit, insert two <p>s. By default, it would insert two <div>s, which would be
// potentially expensive to track down and replace.
if (SC.browser.isWebkit) {
this.insertHtmlAtCaret('<p><br></p><p><br></p>');
}
// If we're Firefox, insert one <p> and allow the default. If we didn't insert the <p>, firefox
// would insert two <br>s and we'd be sunk. If we insert two <p>s like in Webkit, it inserts
// both but positions the caret *after* the second one, causing a third line to appear when the
// user starts typing again.
else if (SC.browser.isMozilla) {
this.insertHtmlAtCaret('<p><br></p>');
evt.allowDefault();
}
}
// Otherwise, let the browser handle that nonsense. (Which, since we've made sure that any extant
// elements are <p>s, it will do correctly.)
else {
evt.allowDefault();
}
evt.allowDefault();
return YES;
},

Expand Down
11 changes: 0 additions & 11 deletions views/wysiwyg_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ SC.WYSIWYGView = SC.View.extend(SC.Control, {
*/
isEditable: YES,

/**
EXPERIMENTAL (see documentation on WYSIWYGEditorView)

@type Boolean
@default NO
@see SC.WYSIWYGEditorView#forceLineBreaks
*/
forceLineBreaks: NO,

/**
@type Boolean
@default NO
Expand Down Expand Up @@ -169,8 +160,6 @@ SC.WYSIWYGView = SC.View.extend(SC.Control, {

pasteAsPlainText: SC.outlet('wysiwygView.pasteAsPlainText'),

forceLineBreaks: SC.outlet('wysiwygView.forceLineBreaks'),

minHeightBinding: SC.Binding.transform(function (frame) {
return frame ? frame.height : 0;
}).oneWay('.parentView.frame')
Expand Down