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.
Insert Tab into code field
- Almost_there
- Posts: 404
- Joined: 30 Sep 2014, 10:32
Re: Insert Tab into code field
I just created a greasemonkey script for you...
try it out:
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 joedf@ahkscript.org (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">'
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Insert Tab into code field
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
Interesting. ill have to try that when I get home.
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
- Almost_there
- Posts: 404
- Joined: 30 Sep 2014, 10:32
Re: Insert Tab into code field
Huh - must test
Thanks - I didn't know that
Code: Select all
;test
; Ok - it work, but only in "advanced mode"
Re: Insert Tab into code field
Lol
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: Insert Tab into code field
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
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
Re: Insert Tab into code field
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
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
Who is online
Users browsing this forum: No registered users and 22 guests