mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 21:38:54 +00:00
[feature/editor-code-tabs] Correctly count indentation on first line
Correctly count indentation on first line of code tag PHPBB3-11557
This commit is contained in:
parent
c25c17adb7
commit
3dae0cfcae
1 changed files with 21 additions and 4 deletions
|
@ -401,7 +401,7 @@ function getCaretPosition(txtarea) {
|
||||||
*/
|
*/
|
||||||
(function($) {
|
(function($) {
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var doc, textarea, startTags, endTags;
|
var doc, textarea, startTags, startTagsEnd, endTags;
|
||||||
|
|
||||||
// find textarea, make sure browser supports necessary functions
|
// find textarea, make sure browser supports necessary functions
|
||||||
if (document.forms[form_name]) {
|
if (document.forms[form_name]) {
|
||||||
|
@ -421,6 +421,7 @@ function getCaretPosition(txtarea) {
|
||||||
|
|
||||||
// list of allowed start and end bbcode code tags, in lower case
|
// list of allowed start and end bbcode code tags, in lower case
|
||||||
startTags = ['[code]', '[code='];
|
startTags = ['[code]', '[code='];
|
||||||
|
startTagsEnd = ']';
|
||||||
endTags = ['[/code]'];
|
endTags = ['[/code]'];
|
||||||
|
|
||||||
function inTag() {
|
function inTag() {
|
||||||
|
@ -450,11 +451,27 @@ function getCaretPosition(txtarea) {
|
||||||
return (lastEnd < lastStart);
|
return (lastEnd < lastStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLastLine() {
|
function getLastLine(stripCodeTags) {
|
||||||
var start = textarea.selectionStart,
|
var start = textarea.selectionStart,
|
||||||
value = textarea.value,
|
value = textarea.value,
|
||||||
index = value.lastIndexOf("\n", start - 1);
|
index = value.lastIndexOf("\n", start - 1);
|
||||||
return value.substring(index + 1, start);
|
value = value.substring(index + 1, start);
|
||||||
|
if (stripCodeTags) {
|
||||||
|
for (var i = 0; i < startTags.length; i++) {
|
||||||
|
index = value.lastIndexOf(startTags[i]);
|
||||||
|
if (index >= 0) {
|
||||||
|
var tagLength = startTags[i].length;
|
||||||
|
value = value.substring(index + tagLength);
|
||||||
|
if (startTags[i].lastIndexOf(startTagsEnd) != tagLength) {
|
||||||
|
index = value.indexOf(startTagsEnd);
|
||||||
|
if (index >= 0) {
|
||||||
|
value = value.substr(index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendCode(code) {
|
function appendCode(code) {
|
||||||
|
@ -480,7 +497,7 @@ function getCaretPosition(txtarea) {
|
||||||
// intercept new line characters
|
// intercept new line characters
|
||||||
if (key == 13) {
|
if (key == 13) {
|
||||||
if (inTag()) {
|
if (inTag()) {
|
||||||
var lastLine = getLastLine(),
|
var lastLine = getLastLine(true),
|
||||||
code = '' + /^\s*/g.exec(lastLine);
|
code = '' + /^\s*/g.exec(lastLine);
|
||||||
if (code.length > 0) {
|
if (code.length > 0) {
|
||||||
appendCode("\n" + code);
|
appendCode("\n" + code);
|
||||||
|
|
Loading…
Add table
Reference in a new issue