2008-08-03, 03:05 PM
It's a major headache working with templates in the adminCP without the ability to insert tab character. I have solved the issue and also added the possibility of code indention for FireFox 3.
Find in admin/jscripts/codepress/engines/gecko.js:
Replace with:
This will allow you to:
If you simply want the option #2, use the following code instead: (It's a bug that I decided to fix, so MyBB should add this code at least)
Enjoy better editing in FF3
Find in admin/jscripts/codepress/engines/gecko.js:
for (var i=0; i<snippets.length; i++) {
if(snippets[i].input == trigger) {
var content = snippets[i].output.replace(/</g,'<');
content = content.replace(/>/g,'>');
if(content.indexOf('$0')<0) content += cc;
else content = content.replace(/\$0/,cc);
content = content.replace(/\n/g,'<br>');
var pattern = new RegExp(trigger+cc,'gi');
evt.preventDefault(); // prevent the tab key from being added
this.syntaxHighlight('snippets',pattern,content);
}
}
Replace with:
// modified to insert tab on FF
var noInsertion = 1;
for (var i=0; i<snippets.length; i++) {
if(snippets[i].input == trigger) {
noInsertion = 0;
var content = snippets[i].output.replace(/</g,'<');
content = content.replace(/>/g,'>');
if(content.indexOf('$0')<0) content += cc;
else content = content.replace(/\$0/,cc);
content = content.replace(/\n/g,'<br>');
var pattern = new RegExp(trigger+cc,'gi');
evt.preventDefault(); // prevent the tab key from being added
this.syntaxHighlight('snippets',pattern,content);
}
}
/* Modified to insert tab on FF
* @author Asad Khan <asadkn [at-the-rate-of] gmail [dot] com>
*/
if (noInsertion == 1) {
var range = window.getSelection().getRangeAt(0);
// code indention for multiple lines...
if (range.commonAncestorContainer.getElementsByTagName) {
var childNodes = range.commonAncestorContainer.getElementsByTagName('*');
var lastBr;
for (var i = 0; i < childNodes.length; i++)
{
srcRange = document.createRange();
srcRange.selectNode(childNodes[i]);
// in range?
if (srcRange.compareBoundaryPoints(Range.START_TO_START, range) >= 0 && srcRange.compareBoundaryPoints(Range.END_TO_END, range) <= 0) {
if (lastBr) {
childNodes[i].innerHTML = '\t' + childNodes[i].innerHTML;
lastBr = '';
}
if (childNodes[i].tagName.toLowerCase() == 'br') {
lastBr = childNodes[i];
}
}
}
}
// for the single line
range.setEnd(range.startContainer, range.startOffset);
var ele = document.createTextNode('\t');
range.insertNode(ele);
range.setStartAfter(ele);
evt.preventDefault();
}
This will allow you to:
- Indent code spanned over multiple lines by selecting the lines and pressing the tab key.
- Use the tab key to add a tab character instead of hopping over the next input area.
If you simply want the option #2, use the following code instead: (It's a bug that I decided to fix, so MyBB should add this code at least)
var range = window.getSelection().getRangeAt(0);
// for the single line
range.setEnd(range.startContainer, range.startOffset);
var ele = document.createTextNode('\t');
range.insertNode(ele);
range.setStartAfter(ele);
evt.preventDefault();
Enjoy better editing in FF3