正如 Diodeus 已经说过的那样,您不能折叠单个角色,如果您想摆脱它,就必须将其剥离。许多浏览器会将连续输入的多个空格“压缩”为一个空格。这意味着即使用户输入了 15 个空格,也只有一个可见空格。这就是tinymce进入受保护空间的原因。现在,所有输入的空间都将以不同类型空间的价格显示。
更新:插入跨度并检查其位置的示例代码。汇总到“左”的值将是您感兴趣的
var ed = this.editor, box = null;
if ( $(ed.getBody()).find('p:first').css('line-height') != 'normal'){
lineHeight = $(ed.getBody()).find('p:first').css('line-height') ;
}
else {
lineHeight = $(ed.getBody()).find('p:first').css('min-height');
}
var lineHeight = lineHeight.substr(0, lineHeight.length -2 );//box.height;
var rng = ed.selection.getRng();
rng.collapse(true);
bm = ed.selection.getBookmark();
$marker = $(ed.getBody()).find('#'+bm.id);
var elem = ed.getDoc().getElementById(bm.id+'_start');
box = elem.getBoundingClientRect();
var doc = ed.getDoc(),
docElem = doc.documentElement,
body = ed.getBody(),
win = ed.getWin(),
clientTop = docElem.clientTop || body.clientTop || 0,
clientLeft = docElem.clientLeft || body.clientLeft || 0,
scrollTop = win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop,
scrollLeft = win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft,
top = box.top + scrollTop - clientTop,
left = box.left + scrollLeft - clientLeft;
// set Bookmark
ed.selection.moveToBookmark(bm);