MarkUnit을 작성하기위한 텍스트 영역과 텍스트 영역에 형식을 삽입하는 버튼으로 구성된 Angular 지시문을 작성했습니다. 클릭하면 텍스트가 현재 선택되어 있지 않은 경우, 버튼 (예를 들어, 굵게)는 다음을 추가한다 : IE 11의 텍스트 영역 선택이 마지막 행에서 제대로 작동하지 않습니다.
**replace text**
이 텍스트 교체가
을 선택 어디에.모든 시나리오에서 예상대로 작동합니다. IE 11에서는 최종 행에서 선택이 발생하지만 첫 번째 행에서는 발생하지 않습니다. 다른 모든 브라우저에서 예상대로 작동하며 IE 11에서이 조건을 제외하고 정상적으로 작동합니다.
var editor = element.find('textarea')[0];
function createWrappingMarkdown(symbol) {
// If text is selected, wrap that text in the provided symbol
// After doing so, set the cursor at the end of the highlight,
// but before the ending symbol(s)
/* This section works fine */
if (editor.selectionStart < editor.selectionEnd) {
var start = editor.selectionStart,
end = editor.selectionEnd;
var value = editor.value.substring(0, start) + symbol +
editor.value.substring(start, end) + symbol +
editor.value.substring(end, editor.value.length);
scope.$evalAsync(function() {
editor.value = value;
editor.focus();
editor.selectionStart = end + symbol.length;
editor.selectionEnd = end + symbol.length;
});
// If no text is highlighted, insert {symbol}replace text{symbol}
// at the current cursor position.
// After inserting, select the text "replace text"
/* This is where the selection is broken in IE 11 */
} else if (editor.selectionStart || editor.selectionStart === 0) {
var start = editor.selectionStart,
message = "replace text";
var value = editor.value.substring(0, start) + symbol +
message + symbol + editor.value.substring(start, editor.value.length);
scope.$evalAsync(function() {
editor.value = value;
setCursorSelect(start + symbol.length, start + symbol.length + message.length);
});
}
}
function setCursorSelect(start, end) {
editor.focus();
if (editor.setSelectionRange) {
editor.setSelectionRange(start, end);
} else {
editor.selectionStart = start;
editor.selectionEnd = end;
}
}
업데이트이 문제에 대한 수정 프로그램에 대한
참조 답변 : 여기
선택을 수행하기위한 지침에서 코드입니다. 이 수정 프로그램을 보여주기 위해 Plunk이 개정되었습니다.