Insert Tab into code field

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Insert Tab into code field

Re: Insert Tab into code field

Post by letconex » 12 Oct 2018, 01:12

Take a look, it works for me, I wanted to send a tab in Word in a table, without going to the next cell, so it just pastes a TAB:

Clipboard = " %A_Tab% " ;MsgBox %Clipboard%
word_array := StrSplit(ClipBoard, A_Space) ; Omits periods.
Clipboard := word_array[2] ; MsgBox X%Clipboard%X
SendInput ^v ; paste tab
Return

Re: Insert Tab into code field

Post by tank » 09 Feb 2017, 11:21

yea this is more a limitation of how browsers handle tab characters by default. which is to switch to the next tab index. its a relic of how ancient word processors worked

Re: Insert Tab into code field

Post by joedf » 23 Jan 2017, 18:55

Lol :+1:

Re: Insert Tab into code field

Post by Almost_there » 23 Jan 2017, 13:27

Huh - must test :geek:

Code: Select all

;test	
	; Ok - it work, but only in "advanced mode"
Thanks - I didn't know that :mrgreen:

Re: Insert Tab into code field

Post by joedf » 23 Jan 2017, 10:23

Interesting. :think: ill have to try that when I get home.

Re: Insert Tab into code field

Post by guest3456 » 23 Jan 2017, 08:45

when within a

Code: Select all

[/c] block, pressing TAB already inserts a tab. when not in a [c][code][/c] block, it tabs to the next element

i'm on Chrome

Re: Insert Tab into code field

Post by joedf » 22 Jan 2017, 21:05

I just created a greasemonkey script for you...
try it out:

Code: Select all

// ==UserScript==
// @name        inserttab button
// @namespace   ahkscriptreplyeditor
// @include     https://autohotkey.com/boards/posting.php?mode=reply*
// @version     1
// @grant       none
// @author      [email protected] (MIT license)
// @description  Adds a "tab" button to insert tabs when using the full reply page on ahk forums
// ==/UserScript==

/*
// Author: http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript
// Modified so it's safe across browser windows
function insertAtCursor(myField, myValue) {
  var doc = myField.ownerDocument;
  //IE support
  if (doc.selection) {
    myField.focus();
    sel = doc.selection.createRange();
    sel.text = myValue;
  }
  //FF, hopefully others
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos) + 
                    myValue + myField.value.substring(endPos, myField.value.length);
  } 
  // fallback to appending it to the field
  else {
    myField.value += myValue;
  }
}

// http://stackoverflow.com/a/512542/883015
function setCaretPosition(elemId, caretPos) {
    var elem = document.getElementById(elemId);

    if(elem != null) {
        if(elem.createTextRange) {
            var range = elem.createTextRange();
            range.move('character', caretPos);
            range.select();
        }
        else {
            if(elem.selectionStart) {
                elem.focus();
                elem.setSelectionRange(caretPos, caretPos);
            }
            else
                elem.focus();
        }
    }
}

// http://stackoverflow.com/a/2897229/883015
function doGetCaretPosition(oField) {

  // Initialize
  var iCaretPos = 0;

  // IE Support
  if (document.selection) {

    // Set focus on the element
    oField.focus();

    // To get cursor position, get empty selection range
    var oSel = document.selection.createRange();

    // Move selection start to 0 position
    oSel.moveStart('character', -oField.value.length);

    // The caret position is selection length
    iCaretPos = oSel.text.length;
  }

  // Firefox support
  else if (oField.selectionStart || oField.selectionStart == '0')
    iCaretPos = oField.selectionStart;

  // Return results
  return iCaretPos;
}

function inserttab() {
  tbox = document.getElementById("message");
  pos = doGetCaretPosition(tbox) + 1;
  insertAtCursor(tbox,"\t");
  tbox.focus();
  setCaretPosition(tbox,pos);
  tbox.focus();
}
*/

//code (but compressed) above is injected

js_inject = "function insertAtCursor(a,b){var c=a.ownerDocument;if(c.selection)a.focus(),sel=c.selection.createRange(),sel.text=b;else if(a.selectionStart||\"0\"==a.selectionStart){var d=a.selectionStart,e=a.selectionEnd;a.value=a.value.substring(0,d)+b+a.value.substring(e,a.value.length)}else a.value+=b}function setCaretPosition(a,b){var c=document.getElementById(a);if(null!=c)if(c.createTextRange){var d=c.createTextRange();d.move(\"character\",b),d.select()}else c.selectionStart?(c.focus(),c.setSelectionRange(b,b)):c.focus()}function doGetCaretPosition(a){var b=0;if(document.selection){a.focus();var c=document.selection.createRange();c.moveStart(\"character\",-a.value.length),b=c.text.length}else(a.selectionStart||\"0\"==a.selectionStart)&&(b=a.selectionStart);return b}function inserttab(){tbox=document.getElementById(\"message\"),pos=doGetCaretPosition(tbox)+1,insertAtCursor(tbox,\"\\t\"),tbox.focus(),setCaretPosition(tbox,pos),tbox.focus()}"

var inserttabjs = document.createElement("script");
inserttabjs.id = "inserttabjs"
inserttabjs.type = "text/javascript"
inserttabjs.innerHTML = js_inject
document.body.appendChild(inserttabjs);


x = document.getElementById("format-buttons").innerHTML
document.getElementById("format-buttons").innerHTML = x + '<input class="button2" value="Tab" onclick="javascript:inserttab()" type="button">'

Insert Tab into code field

Post by Almost_there » 22 Jan 2017, 17:06

Hi.

When editing code directly in forum editor, there is no easy way to insert a tab. Workaround is to copy Tab to clipboard and then paste (or can do that by simple script).

But that means more work for less, so I suggest a button to insert Tab character into test field.

As most web browsers, Firefox that I use does not support insert Tab directly into text fields, but rather select next controller/element.

Top