Scroll to and select first merge conflict in editor
When a user is thrown back to the editor because there are conflicts to handle, the editor is now scrolled to the first conflict automatically. Only tested in Chrome so far.
This commit is contained in:
parent
4e4618a9fd
commit
9ae98fa586
|
@ -331,6 +331,7 @@ function act_save($act){
|
|||
global $SUM;
|
||||
global $lang;
|
||||
global $INFO;
|
||||
global $JSINFO;
|
||||
|
||||
//spam check
|
||||
if(checkwordblock()) {
|
||||
|
@ -344,6 +345,7 @@ function act_save($act){
|
|||
//deny saving when merge markers are present
|
||||
if(preg_match('/^(✎|✏|✐)——————/m',$mine)){
|
||||
msg('Please resolve the conflicts',-1); //FIXME localize
|
||||
$JSINFO['selectConflict'] = 'wiki__text';
|
||||
return 'edit';
|
||||
}
|
||||
|
||||
|
@ -374,6 +376,7 @@ function act_save($act){
|
|||
$TEXT = $final;
|
||||
|
||||
msg('Please resolve the conflicts',-1); //FIXME we'll need more explantion than that
|
||||
$JSINFO['selectConflict'] = 'wiki__text';
|
||||
return 'edit';
|
||||
}
|
||||
// no merge conflicts
|
||||
|
|
|
@ -117,6 +117,7 @@ function js_out(){
|
|||
}
|
||||
js_runonstart('scrollToMarker()');
|
||||
js_runonstart('focusMarker()');
|
||||
js_runonstart('initConflictSelect()');
|
||||
// init hotkeys - must have been done after init of toolbar
|
||||
# disabled for FS#1958 js_runonstart('initializeHotkeys()');
|
||||
|
||||
|
|
|
@ -349,3 +349,50 @@ function summaryCheck(){
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* selects and scrolls to the first conflict marker
|
||||
*
|
||||
* This runs when the global JSINFO array contains a member 'selectConflict'
|
||||
* containing the ID of a textarea to work on
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
function initConflictSelect(){
|
||||
if(!JSINFO.selectConflict) return;
|
||||
var field = $(JSINFO.selectConflict);
|
||||
if(!field) return;
|
||||
|
||||
// find the conflict markers
|
||||
var start = field.value.indexOf('✎—————');
|
||||
if(start < 0) return;
|
||||
var end = field.value.indexOf('✐—————');
|
||||
if(end < 0) {
|
||||
end = start;
|
||||
} else {
|
||||
end += 48;
|
||||
}
|
||||
|
||||
// prepare selection
|
||||
var selection = getSelection(field);
|
||||
selection.start = start;
|
||||
selection.end = end;
|
||||
|
||||
|
||||
// find out how far to scroll to show selection
|
||||
// we need to create a dummy pre tag to let the browser calculate the
|
||||
// scroll height for us
|
||||
// see http://wiki.sheep.art.pl/Textarea%20Scrolling
|
||||
var scrollPre = document.createElement('pre');
|
||||
field.parentNode.appendChild(scrollPre);
|
||||
scrollPre.style = field.style;
|
||||
scrollPre.style.padding = 0;
|
||||
scrollPre.style.overflow = 'scroll';
|
||||
scrollPre.textContent = field.value.substr(0,start);
|
||||
selection.scroll = scrollPre.scrollHeight;
|
||||
scrollPre.parentNode.removeChild(scrollPre);
|
||||
|
||||
// finally set the selection
|
||||
setSelection(selection);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue