Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:summernote/summernote into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
lqez committed May 17, 2020
2 parents fdc29ca + 508fb55 commit 3bc1418
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
9 changes: 1 addition & 8 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=S8F8AAD3YSD6Q&source=url
open_collective: summernote
55 changes: 43 additions & 12 deletions src/js/base/module/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,8 @@ export default class Editor {
}
});

const startRange = range.createFromNodeBefore(lists.head(anchors));
const startPoint = startRange.getStartPoint();
const endRange = range.createFromNodeAfter(lists.last(anchors));
const endPoint = endRange.getEndPoint();

this.setLastRange(
range.create(
startPoint.node,
startPoint.offset,
endPoint.node,
endPoint.offset
).select()
this.createRangeFromList(anchors).select()
);
});

Expand Down Expand Up @@ -497,6 +487,7 @@ export default class Editor {
}
return false;
}

/**
* create range
* @return {WrappedRange}
Expand All @@ -507,6 +498,34 @@ export default class Editor {
return this.getLastRange();
}

/**
* create a new range from the list of elements
*
* @param {list} dom element list
* @return {WrappedRange}
*/
createRangeFromList(lst) {
const startRange = range.createFromNodeBefore(lists.head(lst));
const startPoint = startRange.getStartPoint();
const endRange = range.createFromNodeAfter(lists.last(lst));
const endPoint = endRange.getEndPoint();

return range.create(
startPoint.node,
startPoint.offset,
endPoint.node,
endPoint.offset
);
}

/**
* set the last range
*
* if given rng is exist, set rng as the last range
* or create a new range at the end of the document
*
* @param {WrappedRange} rng
*/
setLastRange(rng) {
if (rng) {
this.lastRange = rng;
Expand All @@ -519,6 +538,14 @@ export default class Editor {
}
}

/**
* get the last range
*
* if there is a saved last range, return it
* or create a new range and return it
*
* @return {WrappedRange}
*/
getLastRange() {
if (!this.lastRange) {
this.setLastRange();
Expand Down Expand Up @@ -803,10 +830,14 @@ export default class Editor {
const firstSpan = lists.head(spans);
if (firstSpan && !dom.nodeLength(firstSpan)) {
firstSpan.innerHTML = dom.ZERO_WIDTH_NBSP_CHAR;
range.createFromNodeAfter(firstSpan.firstChild).select();
range.createFromNode(firstSpan.firstChild).select();
this.setLastRange();
this.$editable.data(KEY_BOGUS, firstSpan);
}
} else {
this.setLastRange(
this.createRangeFromList(spans).select()
);
}
} else {
const noteStatusOutput = $.now();
Expand Down
7 changes: 7 additions & 0 deletions test/base/module/Editor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,13 @@ describe('Editor', () => {
// start <p>hello</p> => <h6 class="h6">hello</h6>
expectContentsAwait(context, '<h6 class="customH6Class">hello</h6>', done);
});

it('should add fontSize to block', () => {
$editable.appendTo('body');
editor.fontSize(20);

expectContents(context, '<p><span style="font-size: 20px;"></span>hello</p>');
});
});

describe('createLink', () => {
Expand Down

0 comments on commit 3bc1418

Please sign in to comment.