0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-06 23:00:08 -05:00

Code style fixed, font detection loop will continue until finding both size and family, and selections within single element are handled.

This commit is contained in:
Gert K. Sønderby 2015-08-31 09:45:25 +02:00
parent 02ff9fe985
commit f6b79eb82b
4 changed files with 12 additions and 10 deletions

View file

@ -181,7 +181,7 @@ Returns the path through the DOM tree from the `<body>` element to the current c
### getFontInfo ### getFontInfo
Returns an object containing the font-family and font-size information for the element the cursor is in, if any was set. It uses style declarations to detect this, and so will not detect FONT tags. If a selection has been made, it will return an empty object. Returns an object containing the font-family and font-size information for the element the cursor is in, if any was set. It uses style declarations to detect this, and so will not detect FONT tags. If a selection across multiple elements has been made, it will return an empty object.
### getSelection ### getSelection

View file

@ -2842,14 +2842,15 @@ proto.getFontInfo = function ( range ) {
return {}; return {};
} }
var element, fontInfo = {}; var fontInfo = {},
element;
if ( range.collapsed ) { if ( range.collapsed || range.startContainer === range.endContainer ) {
element = range.commonAncestorContainer; element = range.commonAncestorContainer;
if ( element.nodeType === TEXT_NODE ) { if ( element.nodeType === TEXT_NODE ) {
element = element.parentNode; element = element.parentNode;
} }
while ( !fontInfo.family && !fontInfo.size && element && element.nodeName !== 'BODY' ) { while ( !( fontInfo.family && fontInfo.size ) && element && element.nodeName !== 'BODY' ) {
if ( element.style.fontFamily ) { if ( element.style.fontFamily ) {
fontInfo.family = element.style.fontFamily; fontInfo.family = element.style.fontFamily;
} }

File diff suppressed because one or more lines are too long

View file

@ -717,14 +717,15 @@ proto.getFontInfo = function ( range ) {
return {}; return {};
} }
var element, fontInfo = {}; var fontInfo = {},
element;
if ( range.collapsed ) { if ( range.collapsed || range.startContainer === range.endContainer ) {
element = range.commonAncestorContainer; element = range.commonAncestorContainer;
if ( element.nodeType === TEXT_NODE ) { if ( element.nodeType === TEXT_NODE ) {
element = element.parentNode; element = element.parentNode;
} }
while ( !fontInfo.family && !fontInfo.size && element && element.nodeName !== 'BODY' ) { while ( !( fontInfo.family && fontInfo.size ) && element && element.nodeName !== 'BODY' ) {
if ( element.style.fontFamily ) { if ( element.style.fontFamily ) {
fontInfo.family = element.style.fontFamily; fontInfo.family = element.style.fontFamily;
} }