New Features:
- Press
Ctrl + Lto get prompted to enter a line number which it will go to. It will highlight the entire line for visibility.- I didn't use
Ctrl + Gbecause it interfered with the browser's search again key shortcut.
- I didn't use
TaborShift + Tabto indent or remove indents with two spaces. Works with highlighting multiple lines.Ctrl + Dduplicate line(s). Works with highlighting multiple lines.Ctrl + Up/DownscrollCtrl + Ssave to file- Enclose highlighted text with:
()[]{}""''`` - Implement custom Undo
Ctrl + Zand RedoCtrl + Yfunctionality because tabbing and duplicating lines is not a text operation where the browser's undo/redo can do it properly.
Sorry that I am "team spaces" over "tabs" but this bugged me. I figured I could copy-paste my code into another editor to apply the tabs, but that took too much time and saw that it wasn't too much effort to implement it as a feature.
This update increased the code by over 1kb! It's a lot, but the features will improve the quality of life so much.
The code got fairly complicated such that I couldn't write it in this minified format. So I wrote it up and then used Terser Online by xem to get it minified. It's a simple Terser so it won't mess with my code except to apply some code minifying techniques. It's awesome and I almost forgot it existed. Such an awesome tool!
I also forgot that I started implementing the "Goto Line" feature in "Part 1" and got it working perfectly. It's kind of fun knowing how to take advantage of a textarea and give it features. I'm pretty sure I can add in autocomplete features too, I just can't think of any meaningful implementations at the moment.
I am hesitant to implement "Find & Replace" because there is already a text search feature on your browser which does text highlighting, but it will not do a replace. I haven't felt that it hinders the little coding projects I do on this tiny app.
There is a balance I want to achieve here. This tiny app is not meant to replace a coding app which will basically do everything else much better. It should allow me to create a tiny prototype of something and then move it on to a VSCode project when it gets sufficiently complex. I could add more features, but how badly do I need them before I can simply switch the editor to something else? Or should I implement features "because I can"?
Anyway, I hope others find this useful!
Copy-paste into your address bar or into a bookmark to save it for later use.
data:text/html,<title>code</title><link rel=icon href='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 99 99"><text y="85" font-size="72">&%23128187;</text></svg>'><body id=b><textarea id=d spellcheck=false style=resize:none;padding-bottom:2em><style>:root{color-scheme:dark}</style>%0d<p id=o></p>%0d<script>%0do.innerHTML = 0;%0d</script></textarea><iframe id=f></iframe><p id=p></p><script>h=Q=N=0,S="selection",O=(e,l=e)=>(A=d[S+"Start"]=e,B=d[S+"End"]=l),F=e=>e.split`\n`,J=e=>e.join`\n`,W=[d.value],M="()[]{}\"\"''``",X=e=>V=d.value=e,d.onkeydown=d.onclick=e=>(P=l=>e.preventDefault(),A=d[S+"Start"],B=d[S+"End"],V=d.value,H=e=>V.substr(0,e),K=e.key,C=e.keyCode,I=e.shiftKey,U=38==C,D=40==C,R=F(V),T=R.length,u=0,G=e=>F(V).reduce((l,t,n)=>(n<e?t.length+1:0)+l,0),Y=F(H(A)).length-2,E=F(H(B)),Z=E.length,10==C&&(f.srcdoc=V),e.ctrlKey&&(13==C&&(f.srcdoc=V),"l"==K&&(P(),L=parseInt(prompt("Goto line")),L=L<0?0:L<T?L:T,m=J(R.slice(0,L)).length,O(m-R[L-1].length,m),E=F(H(B))),"d"==K&&(P(),R.splice(Y+1,0,J(R.filter((e,l)=>l>Y&&l<Z))),X(J(R)),O(G(Y+1),G(Z)-1)),(U||D)&&P(d.scrollTop+=U?-15:D?15:0),"s"==K&&(P(a=document.createElement`a`),(m=prompt("Filename","f.html"))&&(a.href=URL.createObjectURL(new Blob([V],{type:"text/plain"})),a.click(a.download=m),URL.revokeObjectURL(a.href))),((k="z"==K)&&N>0||"y"==K&&N<W.length-1)&&(P(),v=W[k?--N:++N],g=V.length-v.length,V=d.value=v,O(A-g),u=1)),"Tab"==K&&(P(),X(J(R.map((e,l)=>l>Y&&l<Z?I?e.replace(/^ {1,2}/,""):" "+e:e))),O(G(Y+1),G(Z)-1)),(k=M.indexOf(K))%2==0&&(P(),X(V.slice(0,A)+K+V.slice(A,B)+M[k+1]+V.slice(B)),O(A+1,B+1)),V!=W[N]&&!u&&(W=W.slice(0,N+1),W[++N]=V),p.innerHTML="<button onclick=d.click(b.className='mhqr'[++h%4])>H</button> "+(h%4==3?"":`Ln:${E.length}, Col:${E.pop().length+1}, ${A==B?"Pos:"+B:"Sel:"+(B-A)}, Len:${V.length}`))</script><style>*{color-scheme:dark;box-sizing:border-box;margin:0}%23d,%23f{width:50%;height:100%;vertical-align:top}.h>%23d,.h>%23f{width:100%;height:50%}%23p{position:fixed;bottom:1;background:%23333}.q>%23d,.r>%23f{width:100%}.r>%23d,.q>%23f{display:none}To apply the dark mode, you can add color-scheme:dark to the * styling. Otherwise, this is a bare-bones version of an HTML editor with the textarea and iframe sharing half the screen vertically. I could get this even smaller, but I think I've narrowed it down the fewest features without it being too difficult to read and understand the code.
data:text/html,<textarea id=d spellcheck=false onkeypress=e=event;k=e.keyCode;(e.ctrlKey&&k==13)||k==10?f.srcdoc=d.value:0 style=resize:none></textarea><iframe id=f></iframe><style>*{box-sizing:border-box;margin:0}%23d,%23f{width:50%;height:100%;vertical-align:top}I'm not sure if I should override an existing browser keyshortcut or use one that is unused. Turns out there are only two Ctrl keyshortcuts that are unused and that is:
Ctrl + BCtrl + M
- Part 1: π» Address Bar Code Editor Bookmarklet (841b)
- Part 2: π» Address Bar Code Editor Bookmarklet Part 2 (876b) - Keeping It Dark
- Part 3: π» Address Bar Code Editor Bookmarklet Part 3 (988b) - Toggle Horizontal-Vertical Views
- Part 4: π» Address Bar Code Editor Bookmarklet Part 4 (1047b) - Toggle Full Screen Views