diff options
author | Stephen Beaver <sbeaver@netgate.com> | 2016-01-18 12:42:49 -0500 |
---|---|---|
committer | Stephen Beaver <sbeaver@netgate.com> | 2016-01-18 12:43:23 -0500 |
commit | b54c203513b17a87e9cfe5ba8e803eaf3ee47d86 (patch) | |
tree | de383a95f09118bf28c8783dda7044a40013082e /src/usr | |
parent | b12cb9535d0822ebfbcb64e0c865864e1e079a68 (diff) | |
download | pfsense-b54c203513b17a87e9cfe5ba8e803eaf3ee47d86.zip pfsense-b54c203513b17a87e9cfe5ba8e803eaf3ee47d86.tar.gz |
Add "GoTo line #" control
Diffstat (limited to 'src/usr')
-rw-r--r-- | src/usr/local/www/edit.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/usr/local/www/edit.php b/src/usr/local/www/edit.php index fe15105..45fa6c1 100644 --- a/src/usr/local/www/edit.php +++ b/src/usr/local/www/edit.php @@ -128,6 +128,9 @@ require("head.inc"); <input type="button" class="btn btn-default btn-sm" onclick="loadFile();" value="<?=gettext('Load')?>" /> <input type="button" class="btn btn-default btn-sm" id="fbOpen" value="<?=gettext('Browse')?>" /> <input type="button" class="btn btn-default btn-sm" onclick="saveFile();" value="<?=gettext('Save')?>" /> + <span class="pull-right"> + <button id="btngoto" class="btn btn-default btn-sm"><?=gettext("GoTo Line #")?></button> <input type="number" id="gotoline" width="6"></input> + </span> </form> <div id="fbBrowser" style="display:none; border:1px dashed gray; width:98%;"></div> @@ -148,6 +151,58 @@ require("head.inc"); <script type="text/javascript"> //<![CDATA[ + events.push(function(){ + + function showLine(tarea, lineNum) { + + lineNum--; // array starts at 0 + var lines = tarea.value.split("\n"); + + // calculate start/end + var startPos = 0, endPos = tarea.value.length; + for(var x = 0; x < lines.length; x++) { + if(x == lineNum) { + break; + } + startPos += (lines[x].length+1); + + } + + var endPos = lines[lineNum].length+startPos; + + // do selection + // Chrome / Firefox + + if(typeof(tarea.selectionStart) != "undefined") { + tarea.focus(); + tarea.selectionStart = startPos; + tarea.selectionEnd = endPos; + return true; + } + + // IE + if (document.selection && document.selection.createRange) { + tarea.focus(); + tarea.select(); + var range = document.selection.createRange(); + range.collapse(true); + range.moveEnd("character", endPos); + range.moveStart("character", startPos); + range.select(); + return true; + } + + return false; + } + + $("#btngoto").prop('type','button'); + + $('#btngoto').click(function() { + var tarea = document.getElementById("fileContent"); + showLine(tarea, $('#gotoline').val()); + }); + }); + function loadFile() { jQuery("#fileStatus").html(""); jQuery("#fileStatusBox").show(500); |