PageRenderTime 92ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/vi.js

https://github.com/sirvaliance/jsvi
JavaScript | 3801 lines | 3620 code | 94 blank | 87 comment | 740 complexity | c44c7cd22defa7a9e832a99fb2bdedcb MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. JSVI - VI in JavaScript.
  3. Copyright (C) 2006-2008 Internet Connection, Inc.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. */
  16. var version = '1.0';
  17. var emacsen = false;
  18. /* TODO
  19. sortof bugs:
  20. the toolbar is kind of ugly- possibly replace with an image-version-
  21. or more likely- replace with styled buttons
  22. ideas:
  23. uneditable sections?
  24. a ruler at the 72 character mark? possibly word-wrapping?
  25. want to switch between vi/emacs modes?
  26. */
  27. var term_cols;
  28. var term_rows;
  29. var term_win_width;
  30. var term_win_height;
  31. var term_cur_width;
  32. var tools;
  33. var suggest;
  34. var backing;
  35. var tagstyle = 0;
  36. var line_height = 0;
  37. var cclick = undefined;
  38. var mode = 0;
  39. var accum = 0;
  40. var lastaccum = 0;
  41. var marks = new Object();
  42. var registers = new Object();
  43. var lastreg = '';
  44. var lastcommand;
  45. var lastmotion;
  46. var cursoriv;
  47. var drawiv;
  48. var printer;
  49. var term;
  50. var base = 0;
  51. var left = 0;
  52. var vselm = 0;
  53. var vselx = undefined;
  54. var vsely = undefined;
  55. var vseld = false;
  56. var lastkey = undefined;
  57. var statustext = '';
  58. var command = '';
  59. var oldcommand = '';
  60. var commandleft = 0;
  61. var savex, savey;
  62. var once = true;
  63. var cursorx, cursory;
  64. var file = new Array();
  65. var tags = new Array();
  66. var palette;
  67. var cursor;
  68. var yank_buffer = undefined;
  69. var term_save_h = new Array();
  70. var term_save_ss;
  71. var term_save_mc;
  72. var term_save_kd;
  73. var term_save_kp;
  74. var term_save_rs;
  75. var term_save_op;
  76. var lastsearch;
  77. var lastsubst;
  78. var lastflags;
  79. var undoset = undefined;
  80. var undoline = undefined;
  81. var undoy = -1;
  82. var term_ex_motion;
  83. var vi_ft_reg;
  84. var viflags = '';
  85. var lastinsert = '';
  86. var spelling = false;
  87. var spellcheck = new Object();
  88. var safewords = new Object();
  89. var brokenwords = new Object();
  90. var suggestions = new Object();
  91. safewords['jsvi']=true;
  92. safewords['javascript']=true;
  93. safewords['URL']=true;
  94. safewords['hyperlinks']=true;
  95. safewords['HTML']=true;
  96. safewords['UNIX']=true;
  97. safewords['Firefox']=true;
  98. safewords['MSIE']=true;
  99. safewords['Ctrl']=true;
  100. safewords['vi']=true;
  101. safewords['vi-keys']=true;
  102. safewords[':hardcopy']=true;
  103. safewords['unicode-aware']=true;
  104. safewords['developer-centric']=true;
  105. var doing_backing_paste = false;
  106. function _true() { return true; }
  107. function _false() { return false; }
  108. function _cbrestore() {
  109. var i;
  110. for (i = 0; i < term_save_h.length; i++) {
  111. var z = term_save_h[i];
  112. z();
  113. }
  114. term_save_h = new Array();
  115. }
  116. function _cbw(nx,ny) {
  117. var nz = window['on'+nx];
  118. (function(x,y,z) {
  119. term_save_h[term_save_h.length] = function() {
  120. window['on'+x] = z;
  121. };
  122. })(nx,ny,nz);
  123. window['on'+nx]=ny;
  124. }
  125. function _cbd(nx,ny) {
  126. var nz = document['on'+nx];
  127. (function(x,y,z) {
  128. term_save_h[term_save_h.length] = function() {
  129. document['on'+x] = z;
  130. };
  131. })(nx, ny, nz);
  132. document['on'+nx]=ny;
  133. }
  134. function _rer(re,t,aa) {
  135. if (RegExp.rightContext != undefined) return RegExp.rightContext;
  136. // emulate rightContext
  137. var s = re.toString();
  138. if ((s.substr(0,2) == '/^' && s.substr(s.length-1,1) == '/') || s.substr(0,1) == '^') {
  139. // bound at beginning
  140. return t.substr(aa[0].length, t.length - aa[0].length);
  141. }
  142. if ((s.substr(0,1) == '/' && s.substr(s.length-2,2) == '$/') || s.substr(s.length-1,1) == '$') {
  143. // bound at end
  144. return "";
  145. }
  146. var j = t.lastIndexOf(aa[0]);
  147. if (j != -1) return t.substr(j.t.length-j);
  148. return t;
  149. }
  150. function _rel(re,t,aa) {
  151. if (RegExp.leftContext != undefined) return RegExp.leftContext;
  152. // emulate leftContext
  153. var s = re.toString();
  154. if ((s.substr(0,2) == '/^' && s.substr(s.length-1,1) == '/') || s.substr(0,1) == '^') {
  155. // bound at beginning
  156. return "";
  157. }
  158. if ((s.substr(0,1) == '/' && s.substr(s.length-2,2) == '$/') || s.substr(s.length-1,1) == '$') {
  159. // bound at end
  160. return t.substr(0, t.length - aa[0].length);
  161. }
  162. var j = t.indexOf(aa[0]);
  163. if (j != -1) return t.substr(0,j);
  164. return "";
  165. }
  166. function _hra(x) {
  167. var i;
  168. var cx = 0;
  169. var t = '';
  170. var g = '';
  171. for (i = 0; i < x.length; i++) {
  172. var x3 = x.substr(i,3);
  173. var gx = String.fromCharCode(cx);
  174. if (x3 == '<b>') {
  175. cx = cx | 1;
  176. i += 2;
  177. } else if (x3 == '</b') {
  178. cx = (cx | 1) ^ 1;
  179. i += 3;
  180. } else if (x3 == '<u>') {
  181. cx = cx | 2;
  182. i += 2;
  183. } else if (x3 == '</u') {
  184. cx = (cx | 2) ^ 2;
  185. i += 3;
  186. } else if (x3 == '<i>') {
  187. cx = cx | 16;
  188. i += 2;
  189. } else if (x3 == '</i') {
  190. cx = (cx | 16) ^ 16;
  191. i += 3;
  192. } else if (x3 == '<sp') { // <span class="rv">
  193. cx = cx | 4;
  194. i += 16;
  195. } else if (x3 == '</s') { // </span>
  196. cx = (cx | 4) ^ 4;
  197. i += 6;
  198. } else if (x3 == '&am') { // &amp;
  199. t += '&';
  200. g += gx;
  201. i += 4;
  202. } else if (x3 == '&lt') { // &lt;
  203. t += '<';
  204. g += gx;
  205. i += 3;
  206. } else {
  207. t += x.substr(i,1);
  208. g += gx;
  209. }
  210. }
  211. var aa = new Array();
  212. aa[0] = t;
  213. aa[1] = g;
  214. return aa;
  215. }
  216. function _rtf(t,g) {
  217. var cx = 0;
  218. var i;
  219. var o = '';
  220. if (t == undefined) {
  221. t = '';
  222. g = '';
  223. }
  224. for (i = 0; i < t.length; i++) {
  225. var gx = g.substr(i, 1).charCodeAt(0);
  226. var tx = t.substr(i, 1);
  227. if (tx == "<") tx = "&lt;";
  228. else if (tx == '&') tx = '&amp;';
  229. if (gx != cx) {
  230. if ((gx & 1) && !(cx & 1)) {
  231. o += "<b>";
  232. } else if (!(gx & 1) && (cx & 1)) {
  233. o += "</b>";
  234. }
  235. if ((gx & 2) && !(cx & 2)) {
  236. o += "<u>";
  237. } else if (!(gx & 2) && (cx & 2)) {
  238. o += "</u>";
  239. }
  240. if ((gx & 4) && !(cx & 4)) {
  241. o += "<span class=\"rv\">";
  242. } else if (!(gx & 4) && (cx & 4)) {
  243. o += "</span>";
  244. }
  245. if ((gx & 16) && !(cx & 16)) {
  246. o += "<i>";
  247. } else if (!(gx & 16) && (cx & 16)) {
  248. o += "</i>";
  249. }
  250. cx = gx;
  251. }
  252. o += tx;
  253. }
  254. return o;
  255. }
  256. function _rtfl(y) {
  257. return _rtf(file[y],tags[y]);
  258. }
  259. function _dfx(q) {
  260. /*@cc_on @*/
  261. /*@if (1) return
  262. @end @*/
  263. q.style.position = 'fixed';
  264. }
  265. function term_freeze() {
  266. var i;
  267. var o = '';
  268. for (i = 0; i < file.length; i++) {
  269. o += _rtfl(i)+"\n";
  270. }
  271. return o;
  272. }
  273. function _term_update_printer() {
  274. var i;
  275. var o = '';
  276. for (i = 0; i < file.length; i++) {
  277. o += _rtfl(i)+"<br/>";
  278. }
  279. printer.innerHTML = o;
  280. }
  281. function term_thaw(s) {
  282. var a = s.split("\n");
  283. var i;
  284. var aa;
  285. file = new Array();
  286. tags = new Array();
  287. var o = '';
  288. for (i = 0; i < a.length; i++) {
  289. o += a[i] + "<br/>";
  290. aa = _hra(a[i]);
  291. file[i] = aa[0];
  292. tags[i] = aa[1];
  293. }
  294. printer.innerHTML = o;
  295. }
  296. function _mxo(z,y) {
  297. var i;
  298. var o = '';
  299. for (i = 0; i < z.length; i++) {
  300. o += String.fromCharCode(z.substr(i, 1).charCodeAt(0) | y);
  301. }
  302. return o;
  303. }
  304. function _mxs(n,y) {
  305. var z = String.fromCharCode(y);
  306. var i;
  307. var o = '';
  308. for (i = 0; i < n; i++) {
  309. o += z;
  310. }
  311. return o;
  312. }
  313. function _zeros(n) {
  314. return _mxs(n,0);
  315. }
  316. function _fauc() {
  317. var d = document.getElementsByTagName('A');
  318. var i;
  319. for (i = 0; i < d.length; i++) {
  320. var j = d[i];
  321. if (j._len && j._term) {
  322. if (j._row == (base+cursory) && (left+cursorx) >= j._col && (left+cursorx) <= (j._col+j._len)) {
  323. return j;
  324. }
  325. }
  326. }
  327. return undefined;
  328. }
  329. function _pass_click(e) {
  330. var z = _fauc();
  331. if (z && z.onclick) return z.onclick();
  332. return false;
  333. }
  334. function _pass_dblclick(e) {
  335. var z = _fauc();
  336. if (z && z.ondblclick) return z.ondblclick();
  337. return false;
  338. }
  339. function _cancel_ev(e) {
  340. if (!e) e = window.event;
  341. if (!e) return false;
  342. if (e.preventDefault) e.preventDefault();
  343. if (e.stopPropagation) e.stopPropagation();
  344. return false;
  345. }
  346. function _willclick(e) {
  347. if (window.event) {
  348. if (!e) e = window.event;
  349. }
  350. if (!e) return true;
  351. if (cclick != undefined) window.clearTimeout(cclick);
  352. var x = e.clientX;
  353. var y = e.clientY;
  354. cclick = window.setTimeout(function() {
  355. cclick=undefined;
  356. _cursortoxy(x,y);
  357. }, 200);
  358. return false;
  359. }
  360. function _subclick(e) {
  361. return _willclick(e);
  362. }
  363. function _srep(e) {
  364. if (!e) e = window.event;
  365. if (e.preventDefault) e.preventDefault();
  366. if (e.stopPropagation) e.stopPropagation();
  367. e.cancelBubble=true;
  368. var y = this._row;
  369. var x = this._col;
  370. var len = this._len;
  371. var rep = this._word;
  372. var t = (file[y]);
  373. var g = (tags[y]);
  374. var w = (t.substr(x, len));
  375. var st = (g.substr(x, len));
  376. while (st.length < rep.length) {
  377. st = st + st;
  378. }
  379. if (st.length > rep.length) {
  380. st = st.substr(0, rep.length);
  381. }
  382. term_save_undo(); // save undo!
  383. file[y] = t.substr(0, x) + rep + t.substr(x+len, t.length-(x+len));
  384. tags[y] = g.substr(0, x) + st + g.substr(x+len, t.length-(x+len));
  385. suggest.style.display = 'none';
  386. suggest._visible = false;
  387. while (suggest.firstChild) suggest.removeChild(suggest.firstChild);
  388. if (w == rep) {
  389. statustext = '';
  390. } else {
  391. statustext = 'Replaced "' + w + '" with "' + rep + '"';
  392. }
  393. term_redraw();
  394. return false;
  395. }
  396. function _rl(w,h) {
  397. var x = document.createElement('DIV');
  398. x.style.overflow = 'hidden';
  399. x.style.height = h + 'px';
  400. x.style.marginLeft = w + 'px';
  401. x.style.marginRight = w + 'px';
  402. x.style.backgroundColor = palette[0];
  403. x.style.display = 'block';
  404. x.style.innerHTML = '&nbsp;';
  405. x.style.fontFamily = 'monospace';
  406. return x;
  407. }
  408. function _ruo(t) {
  409. this.style.color = palette[0];
  410. this.style.backgroundColor = palette[1];
  411. }
  412. function _rux(t) {
  413. this.style.color = palette[1];
  414. this.style.backgroundColor = palette[0];
  415. }
  416. function _openurl(e) {
  417. var u = this._term;
  418. window.open(u,'_new');
  419. return true;
  420. }
  421. function _suggest(e) {
  422. var z = this;
  423. if (window.event) {
  424. if (!e) e = window.event;
  425. }
  426. if (e) {
  427. if (e.preventDefault) e.preventDefault();
  428. if (e.stopPropagation) e.stopPropagation();
  429. e.cancelBubble=true;
  430. }
  431. (function(q) {
  432. window.setTimeout(function(){
  433. _dosuggest(q);
  434. }, 10);
  435. })(z);
  436. return false;
  437. }
  438. function _dosuggest(z) {
  439. var x = 0;
  440. var y = 0;
  441. var xt = z._term;
  442. var wrow = z._row;
  443. var wcol = z._col;
  444. var wlen = z._len;
  445. while (z && z != document.body) {
  446. x += z.offsetLeft;
  447. y += z.offsetTop;
  448. z = z.offsetParent;
  449. }
  450. suggest._visible = true;
  451. suggest.style.top = y + 'px';
  452. suggest.style.left = x + 'px';
  453. suggest.style.display = 'block';
  454. suggest.style.zIndex = '3';
  455. suggest.style.padding = '2px';
  456. while (suggest.firstChild) suggest.removeChild(suggest.firstChild);
  457. var sg = document.createElement('DIV');
  458. sg.style.backgroundColor = palette[0];
  459. sg.style.color = palette[1];
  460. sg.style.fontSize = '100%';
  461. sg.style.padding = '2px';
  462. sg.style.textAlign = 'center';
  463. sg.style.cursor = 'default';
  464. var sa = suggestions[xt];
  465. var i;
  466. var fs = 200;
  467. var fd = parseInt((100 / sa.length) * 1.5);
  468. var bf;
  469. for (i = 0; i < sa.length; i++) {
  470. var da = document.createElement('A');
  471. da.href = 'javascript:void(0)';
  472. da.onclick = _srep;
  473. da._word = sa[i];
  474. da._row = wrow;
  475. da._col = wcol;
  476. da._len = wlen;
  477. da.onmouseover = _ruo;
  478. da.onmouseout = _rux;
  479. da.style.margin = '4px';
  480. da.style.textDecoration = 'none';
  481. da.style.display = 'block';
  482. da.style.color = palette[1];
  483. da.style.backgroundColor = palette[0];
  484. da.style.fontSize = fs + '%';
  485. fs -= fd;
  486. if (fs <= 100) fs = 100;
  487. da.appendChild(document.createTextNode(sa[i]));
  488. // err...
  489. da.appendChild(document.createElement('BR'));
  490. if ((wrow-base) > term_rows-(sa.length+1)) {
  491. sg.insertBefore(da, sg.firstChild);
  492. bf = true;
  493. } else if (((i % 2) == 0) || (wrow < (sa.length+1))) {
  494. sg.appendChild(da);
  495. } else {
  496. sg.insertBefore(da, sg.firstChild);
  497. }
  498. da = undefined; // break
  499. }
  500. if (sa.length == 0) {
  501. sg.appendChild(document.createTextNode('No matches'));
  502. }
  503. var da = document.createElement('A');
  504. da.href = 'javascript:void(0)';
  505. da.onclick = _srep;
  506. da._word = xt;
  507. da._row = wrow;
  508. da._col = wcol;
  509. da._len = wlen;
  510. da.style.margin= '4px';
  511. da.style.textDecoration = 'none';
  512. da.style.color = palette[1];
  513. da.style.backgroundColor = palette[0];
  514. da.style.borderBottom = '1px dashed red';
  515. da.style.fontSize = '100%';
  516. da.onmouseover = _ruo;
  517. da.onmouseout = _rux;
  518. da.appendChild(document.createTextNode(xt));
  519. if (wrow > term_rows-(sa.length+1)) {
  520. sg.insertBefore(da, sg.firstChild);
  521. } else {
  522. sg.appendChild(da);
  523. }
  524. // rounded top and bottom
  525. suggest.appendChild(_rl(3,1));
  526. suggest.appendChild(_rl(2,1));
  527. suggest.appendChild(_rl(1,2));
  528. suggest.appendChild(sg);
  529. suggest.appendChild(_rl(1,2));
  530. suggest.appendChild(_rl(2,1));
  531. suggest.appendChild(_rl(3,1));
  532. // msie needs to recalculate these things manually... grr...
  533. // this doesn't work because msie doesn't calculate offsetwidth (thtphtpht)
  534. var zq;
  535. var mw = 11;
  536. if (mw < xt.length) mw = xt.length;
  537. for (i = 0; i < sa.length; i++) {
  538. if (mw < sa[i].length) mw = sa[i].length;
  539. }
  540. if (mw) {
  541. mw *= (term_cur_width*2);
  542. mw += 16;
  543. suggest.style.width = mw + 'px';
  544. }
  545. var sx = parseInt(sg.offsetWidth / 4);
  546. if (x < sx) {
  547. x = 0;
  548. } else {
  549. x -= sx;
  550. suggest.style.left = x + 'px';
  551. }
  552. var sy = parseInt(sg.offsetHeight / 4);
  553. if (bf) {
  554. suggest.style.top = '';
  555. suggest.style.bottom = '0px';
  556. } else if (y < sy) {
  557. y = 0;
  558. suggest.style.top = '0px';
  559. suggest.style.bottom = '';
  560. } else {
  561. y -= sy;
  562. suggest.style.top = y + 'px';
  563. suggest.style.bottom = '';
  564. }
  565. statustext = 'Suggestions for: ' + xt;
  566. term_redraw();
  567. da = undefined; // break
  568. sg = undefined; // break
  569. }
  570. function _backing_paste_real() {
  571. doing_backing_paste = false;
  572. term_redraw();
  573. if (!backing.value) return;
  574. if (backing._lastvalue == backing.value) {
  575. return;
  576. }
  577. backing._lastvalue = backing.value;
  578. term_paste(false, backing.value);
  579. term_redraw();
  580. }
  581. function _msie_paste() {
  582. var chunk = "new content associated with this object";
  583. event.returnValue = false;
  584. term_paste(false, window.clipboardData.getData("Text", chunk));
  585. }
  586. function _backing_paste() {
  587. _update_backing();
  588. if (!doing_backing_paste) {
  589. doing_backing_paste = true;
  590. window.setTimeout(_backing_paste_real, 10);
  591. }
  592. }
  593. function _update_backing() {
  594. if (!backing) return;
  595. /*@cc_on @*/
  596. /*@if (1) return
  597. @end @*/
  598. backing.focus();
  599. backing.select();
  600. }
  601. function _yaty(y) {
  602. if (line_height) return parseInt(y/line_height);
  603. var zx;
  604. var qx = term.firstChild;
  605. var nh = 0;
  606. while (qx && qx != document.body) {
  607. nh += qx.offsetTop;
  608. qx = qx.offsetParent;
  609. }
  610. var ny = 0;
  611. var cy = 0;
  612. for (zx = term.firstChild; zx; zx = zx.nextSibling) {
  613. nh += (zx.offsetHeight + 4);
  614. if (y <= nh) {
  615. cy = ny;
  616. break;
  617. }
  618. ny++;
  619. }
  620. return cy;
  621. }
  622. function _cursortoxy(x,y) {
  623. // this is a little gross...
  624. var sx = cursorx;
  625. cursorx = parseInt(x / term_cur_width);
  626. term_redraw();
  627. var sy = cursory;
  628. cursory = _yaty(y);
  629. if (cursory >= (term_rows-1)) {
  630. cursory = sy;
  631. cursorx = sx;
  632. sy = 0;
  633. }
  634. term_scrollto();
  635. term_calcx();
  636. if (cursory != sy) {
  637. term_redraw();
  638. } else {
  639. term_calcy();
  640. }
  641. _update_backing();
  642. return true;
  643. }
  644. function _mousescroll(e) {
  645. if (!e) e = window.event;
  646. var d = 0;
  647. if (e.wheelDelta) {
  648. d = e.wheelDelta;
  649. if (d < 0) d = 1; else d = -1;
  650. } else if (e.detail) {
  651. d = e.detail;
  652. } else {
  653. return true;
  654. }
  655. if (d < 0) {
  656. if (base > 0) base--;
  657. } else if (d > 0) {
  658. if (base < (file.length - (term_rows-1))) base++;
  659. }
  660. term_redraw();
  661. return false;
  662. }
  663. function _mousedown(e) {
  664. if (suggest._visible) return true;
  665. if (!e) e = window.event;
  666. var y = _yaty(e.clientY);
  667. if (y >= (term_rows-1)) return true;
  668. _willclick(e);
  669. vseld = true;
  670. vselm = 0;
  671. vselx = undefined;
  672. vsely = undefined;
  673. return false;
  674. }
  675. function _mousemove(e) {
  676. if (!e) e = window.event;
  677. if (e) {
  678. if (e.preventDefault) e.preventDefault();
  679. if (e.stopPropagation) e.stopPropagation();
  680. e.cancelBubble=true;
  681. }
  682. if (window.getSelection) {
  683. var s = window.getSelection();
  684. if (s.removeAllRanges) s.removeAllRanges();
  685. }
  686. if (document.selection && document.selection.empty) {
  687. eval('try{document.selection.empty();}catch(e){}');
  688. }
  689. // fixup selection
  690. _update_backing();
  691. if (suggest._visible || !vseld) return true;
  692. if (vseld) {
  693. if (vselx == undefined && vsely == undefined) {
  694. // turn on v here
  695. vselm = 1;
  696. vselx = cursorx+left;
  697. vsely = cursory+base;
  698. }
  699. _willclick(e);
  700. return true;
  701. }
  702. return true;
  703. }
  704. function _mouseup(e) {
  705. if (suggest._visible || !vseld) return true;
  706. vseld = false;
  707. if (vselm && vselx != undefined && vsely != undefined) {
  708. // okay, we HAVE selection
  709. var rr = lastreg;
  710. lastreg = '*';
  711. term_vi_set('y');
  712. term_vi_unset('d');
  713. term_select();
  714. term_operate();
  715. lastreg = rr;
  716. } else {
  717. vselm = 0;
  718. }
  719. _willclick(e);
  720. return false;
  721. }
  722. function _mouseclick(e) {
  723. if (!e) e = window.event;
  724. var y = _yaty(e.clientY);
  725. if (y >= (term_rows-1)) return true;
  726. vselm = 0;
  727. _cursorto(e);
  728. return true;
  729. }
  730. function _cursorto(e) {
  731. if (!e) e = window.event;
  732. var x = e.clientX;
  733. var y = e.clientY;
  734. if (suggest._visible) {
  735. suggest.style.display = 'none';
  736. suggest._visible = false;
  737. statustext = '';
  738. }
  739. return _cursortoxy(x,y);
  740. }
  741. function _word(s) {
  742. var t = s.replace(/[.?!,:]*$/,"");
  743. if (t) s = t;
  744. t = s.replace(/[ \r\n\t]/,"");
  745. if (t) s = t;
  746. return s;
  747. }
  748. function _safe(s) {
  749. if (s.match(/^[ \r\n\t]*<.*>[ \r\n\t]*$/)) return true;
  750. return false;
  751. }
  752. function _xhttp() {
  753. var xmlhttp=false;
  754. /*@cc_on @*/
  755. /*@if (@_jscript_version >= 5)
  756. try {
  757. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  758. } catch (e) {
  759. try {
  760. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  761. } catch (E) {
  762. xmlhttp = false;
  763. }
  764. }
  765. @end @*/
  766. if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  767. xmlhttp = new XMLHttpRequest();
  768. }
  769. if (!xmlhttp) return new Object(); // fake out caller
  770. return xmlhttp;
  771. }
  772. function term_setmode(n) {
  773. mode = n;
  774. lastinsert = '';
  775. }
  776. function term_roll_yank() {
  777. registers["9"] = registers["8"];
  778. registers["8"] = registers["7"];
  779. registers["7"] = registers["6"];
  780. registers["6"] = registers["5"];
  781. registers["5"] = registers["4"];
  782. registers["4"] = registers["3"];
  783. registers["3"] = registers["2"];
  784. registers["2"] = registers["1"];
  785. registers["1"] = registers["0"];
  786. if (lastreg == '0') {
  787. registers[""] = yank_buffer;
  788. }
  789. if (lastreg == "" || lastreg == "*") {
  790. backing._lastvalue = yank_buffer;
  791. backing.value = yank_buffer;
  792. }
  793. registers["0"] = yank_buffer;
  794. }
  795. function term_justify() {
  796. var y = cursory+base;
  797. var i;
  798. if (!accum) accum = 1;
  799. var t = (file[y]);
  800. file[p] = t.replace(/[ ][ ]*$/,"");
  801. tags[p] = tags[p].substr(0, file[p].length);
  802. for (i = 0; i < accum; i++) {
  803. var t = file[i+y+1];
  804. var g = tags[i+y+1];
  805. term_delete(i+y+1); // ignore return
  806. t = t.replace(/^[ ][ ]*/,"");
  807. g = g.substr(g.length - t.length, t.length);
  808. if (t != '') {
  809. file[y] = file[y] + " " + t;
  810. tags[y] = tags[y] + "\0" + g;
  811. }
  812. }
  813. file[y] = file[y].replace(/^[ ][ ]*/,"");
  814. tags[y] = tags[y].substr(tags[y].length - file[y].length, file[y].length);
  815. accum = 0;
  816. }
  817. function term_vi_bb() {
  818. return term_skipbackward(/[ ][^ ][^ ]*[ ]*$/);
  819. }
  820. function term_vi_b() {
  821. return term_skipbackward(/[^a-zA-Z0-9_][a-zA-Z0-9_][a-zA-Z0-9_]*[^a-zA-Z0-9_]*$/);
  822. }
  823. function term_vi_tt() {
  824. var t = (file[cursory+base]);
  825. var i;
  826. var w = term_cols;
  827. for (i = (cursorx+left)-1; i >= 0; i--) {
  828. var c = (t.substr(i, 1));
  829. if (c == vi_ft_reg) {
  830. cursorx = (i - left)+1;
  831. if (cursorx >= w) {
  832. left = 0;
  833. cursorx = i+1;
  834. }
  835. return true;
  836. }
  837. }
  838. return false;
  839. }
  840. function term_vi_t() {
  841. var t = (file[cursory+base]);
  842. var i;
  843. for (i = (cursorx+left)+1; i < t.length; i++) {
  844. var c = (t.substr(i, 1));
  845. if (c == vi_ft_reg) {
  846. cursorx = (i - left)-1;
  847. if (term_vi_flag('d') || term_vi_flag('c') || term_vi_flag('y')) cursorx++;
  848. if (cursorx < 0) {
  849. left = 0;
  850. cursorx = i-1;
  851. }
  852. return true;
  853. }
  854. }
  855. return false;
  856. }
  857. function term_vi_ff() {
  858. var t = (file[cursory+base]);
  859. var i;
  860. for (i = (cursorx+left)-1; i >= 0; i--) {
  861. var c = (t.substr(i, 1));
  862. if (c == vi_ft_reg) {
  863. cursorx = i - left;
  864. if (cursorx < 0) {
  865. left = 0;
  866. cursorx = i;
  867. }
  868. return true;
  869. }
  870. }
  871. return false;
  872. }
  873. function term_vi_f() {
  874. var t = (file[cursory+base]);
  875. var i;
  876. var w = term_cols;
  877. for (i = (cursorx+left)+1; i < t.length; i++) {
  878. var c = (t.substr(i, 1));
  879. if (c == vi_ft_reg) {
  880. cursorx = i - left;
  881. if (term_vi_flag('d') || term_vi_flag('c') || term_vi_flag('y')) cursorx++;
  882. if (cursorx >= w) {
  883. left = 0;
  884. cursorx = i;
  885. }
  886. return true;
  887. }
  888. }
  889. return false;
  890. }
  891. function term_vi_eof() {
  892. cursorx = 0;
  893. left = 0;
  894. base = 0;
  895. if (accum) {
  896. cursory = accum-1;
  897. return false;
  898. } else {
  899. base = file.length - (term_rows-1);
  900. cursory = term_rows-1;
  901. if (base < 0) {
  902. base = 0;
  903. cursory = file.length-1;
  904. }
  905. }
  906. term_redraw();
  907. return true;
  908. }
  909. function term_vi_top() {
  910. cursorx = 0;
  911. base = 0;
  912. left = 0;
  913. if (accum) {
  914. cursory = accum-1;
  915. return false;
  916. } else {
  917. cursory = 0;
  918. }
  919. return true;
  920. }
  921. function term_vi_h() { cursorx--; term_scrollto(); return true; }
  922. function term_vi_j() { cursory++; term_scrollto(); return true; }
  923. function term_vi_k() { cursory--; term_scrollto(); return true; }
  924. function term_vi_l() {
  925. cursorx++;
  926. // hack
  927. var a = mode;
  928. mode = 1;
  929. term_scrollto();
  930. mode = a;
  931. return true;
  932. }
  933. function term_vi_ll() {
  934. cursory = term_rows-2;
  935. return true;
  936. }
  937. function term_vi_mm() {
  938. cursory = parseInt((term_rows-2) / 2);
  939. cursorx = 0; left = 0;
  940. return true;
  941. }
  942. function term_vi_hh() {
  943. cursory = 0;
  944. return true;
  945. }
  946. function term_vi_ob() {
  947. cursory--;
  948. return term_skipreverse2(/^[ ]*$/, 0);
  949. }
  950. function term_vi_cb() {
  951. cursory++;
  952. return term_skipforward(/^[ ]*$/, 0);
  953. }
  954. function term_vi_ww() {
  955. return term_skipforward(/[ ][^ ]/, 0);
  956. }
  957. function term_vi_w() {
  958. return term_skipforward(/[^a-zA-Z0-9_(){}<>][a-zA-Z0-9_(){}<>]/, 0);
  959. }
  960. function term_vi_flag(f) {
  961. return (viflags.indexOf(f) == -1) ? false : true;
  962. }
  963. function term_vi_unset(f) {
  964. var j = viflags.indexOf(f);
  965. if (j == -1) return;
  966. viflags = viflags.substr(0, j) + viflags.substr(j+1, (viflags.length-j)-1);
  967. }
  968. function term_vi_set(f) {
  969. if (viflags.indexOf(f) == -1) viflags += ''+f;
  970. }
  971. function term_vi_bounce() {
  972. var y = cursory+base;
  973. var t = (file[y]);
  974. var x = cursorx+left;
  975. var z1 = '[{()}]';
  976. var z2 = ']})({[';
  977. while (x < t.length) {
  978. var z = z1.indexOf(t.substr(x,1));
  979. if (z == -1) {
  980. x++;
  981. continue;
  982. }
  983. var d = (z > 2) ? -1 : 1;
  984. var c=z2.substr(z,1);
  985. while (y >= 0 && y < file.length) {
  986. while (x > 0 && x < t.length) {
  987. if (t.substr(x,1) == c) {
  988. cursorx = x-left;
  989. cursory = y;
  990. base = 0;
  991. term_scrollto();
  992. return true;
  993. }
  994. x += d;
  995. }
  996. if (d == -1) {
  997. y--;
  998. t = file[y];
  999. x = (t.length-1)
  1000. } else {
  1001. y++;
  1002. t = file[y];
  1003. x = 0;
  1004. }
  1005. }
  1006. }
  1007. return false;
  1008. }
  1009. function term_vi_eol() {
  1010. var t = (file[cursory+base]);
  1011. cursorx = (t.length)-left;
  1012. if (cursorx < 0) {
  1013. left = 0;
  1014. cursorx = (t.length);
  1015. }
  1016. return true;
  1017. }
  1018. function term_vi_line() {
  1019. var t = (file[cursory+base]);
  1020. left = 0;
  1021. cursorx = t.length+1;
  1022. return true;
  1023. }
  1024. function term_vi_ee() {
  1025. return term_skipforward(/[^ ][ ]/, 1);
  1026. }
  1027. function term_vi_e() {
  1028. if (term_skipforward(/[a-zA-Z0-9_(){}<>][^a-zA-Z0-9_(){}<>]/, 1)) {
  1029. if (term_vi_flag('d') || term_vi_flag('c') || term_vi_flag('y')) cursorx++;
  1030. return true;
  1031. }
  1032. return false;
  1033. }
  1034. function term_vi_v() {
  1035. cursorx = vselx - left;
  1036. if (cursorx < 0) {
  1037. left = 0;
  1038. cursorx = vselx;
  1039. }
  1040. cursory = vsely - base;
  1041. if (cursory < 0) {
  1042. base = 0;
  1043. cursory = vsely;
  1044. }
  1045. }
  1046. function term_vi_vv() {
  1047. term_vi_v();
  1048. term_vi_line();
  1049. }
  1050. function term_select() {
  1051. if (vselm == 1) {
  1052. term_ex_motion = term_vi_v;
  1053. } else if (vselm == 2) {
  1054. term_ex_motion = term_vi_vv;
  1055. cursorx = 0;
  1056. left = 0;
  1057. }
  1058. }
  1059. function term_indent(y,amount) {
  1060. if (file[y] == undefined) {
  1061. file[y] = '';
  1062. tags[y] = '';
  1063. }
  1064. file[y] = _mxs(amount*4,32)+file[y];
  1065. tags[y] = _mxs(amount*4,tagstyle)+tags[y];
  1066. }
  1067. function term_unindent(y,amount) {
  1068. amount*=4;
  1069. while (amount > 0 && file[y].substr(0, 1) == ' ') {
  1070. file[y] = file[y].substr(1, file[y].length-1);
  1071. amount--;
  1072. }
  1073. }
  1074. function term_operate() {
  1075. term_save_undo();
  1076. var fa = accum;
  1077. if (!fa) fa = 1;
  1078. var sx = cursorx+left;
  1079. var sy = cursory+base;
  1080. while (fa > 0) {
  1081. var t = file[base+cursory];
  1082. if (t == undefined) break;
  1083. if (fa > 1 && ((cursorx+left) >= t.length)) {
  1084. cursory++;
  1085. cursorx = 0;
  1086. left = 0;
  1087. }
  1088. term_ex_motion();
  1089. fa--;
  1090. }
  1091. fa = accum;
  1092. if (!fa) fa = 1;
  1093. accum = 0;
  1094. var ex = cursorx+left;
  1095. var ey = cursory+base;
  1096. var i;
  1097. if (ey < sy) {
  1098. i = ey;
  1099. ey = sy;
  1100. sy = i;
  1101. }
  1102. if (ex < sx) {
  1103. i = ex;
  1104. ex = sx;
  1105. sx = i;
  1106. }
  1107. var t = file[ey];
  1108. var g = tags[ey];
  1109. var restore = false;
  1110. if (term_vi_flag('c')) term_vi_set('d');
  1111. if (vselm != 2 && ey == sy && ex <= t.length) {
  1112. if (vselm) ex++;
  1113. if (ex != sx) {
  1114. if (term_vi_flag('F')) {
  1115. // styling
  1116. tags[ey] = (g.substr(0, sx)) + _mxs(ex-sx, tagstyle) + (g.substr(ex, g.length-ex));
  1117. } else if (term_vi_flag('d') || term_vi_flag('y')) {
  1118. yank_buffer = _rtf(t.substr(sx, ex-sx),
  1119. g.substr(sx,ex-sx));
  1120. }
  1121. if (term_vi_flag('d')) {
  1122. file[ey] = (t.substr(0, sx)) + (t.substr(ex, t.length-ex));
  1123. tags[ey] = (g.substr(0, sx)) + (g.substr(ex, g.length-ex));
  1124. if (lastreg != '_') {
  1125. registers[lastreg] = yank_buffer;
  1126. term_roll_yank();
  1127. }
  1128. } else if (term_vi_flag('y')) {
  1129. registers[lastreg] = yank_buffer;
  1130. term_roll_yank();
  1131. }
  1132. if (term_vi_flag('>')) {
  1133. term_indent(ey,fa);
  1134. } else if (term_vi_flag('<')) {
  1135. term_unindent(ey,fa);
  1136. }
  1137. }
  1138. } else if (vselm == 1) {
  1139. if (term_vi_flag('d') || term_vi_flag('y') || term_vi_flag('F')) {
  1140. yank_buffer = '';
  1141. var al, bl;
  1142. for (i = sy; i <= ey; i++) {
  1143. t = file[i];
  1144. g = tags[i];
  1145. if (i == sy) {
  1146. if ((sy == vsely && sx == vselx) || (sy != vsely && sx != vselx)) {
  1147. al = sx;
  1148. } else {
  1149. al = ex;
  1150. }
  1151. bl = t.length;
  1152. } else if (i == ey) {
  1153. al = 0;
  1154. if ((sy == vsely && sx == vselx) || (sy != vsely && sx != vselx)) {
  1155. al = ex;
  1156. } else {
  1157. al = sx;
  1158. }
  1159. } else {
  1160. al = 0;
  1161. bl = t.length;
  1162. }
  1163. yank_buffer += _rtf(t.substr(al, bl-al),
  1164. g.substr(al,bl-al));
  1165. if (sy != ey || vselm == 2) yank_buffer += "\n";
  1166. if (term_vi_flag('d')) {
  1167. file[i] = t.substr(0, al) + t.substr(bl, t.length-bl);
  1168. tags[i] = g.substr(0, al) + g.substr(bl, g.length-bl);
  1169. } else if (term_vi_flag('F')) {
  1170. tags[i] = g.substr(0, al) + _mxs(bl-al, tagstyle)
  1171. + g.substr(bl, g.length-bl);
  1172. }
  1173. if (term_vi_flag('>')) {
  1174. term_indent(i,fa);
  1175. } else if (term_vi_flag('<')) {
  1176. term_unindent(i,fa);
  1177. }
  1178. }
  1179. if (lastreg != '_' && !term_vi_flag('F')) {
  1180. registers[lastreg] = yank_buffer;
  1181. term_roll_yank();
  1182. }
  1183. }
  1184. } else {
  1185. if (term_vi_flag('F')) {
  1186. for (i = sy; i <= ey; i++) {
  1187. tags[i] = _mxs(file[i].length, tagstyle);
  1188. }
  1189. } else if (term_vi_flag('d')) {
  1190. yank_buffer = '';
  1191. for (i = sy; i <= ey; i++) {
  1192. yank_buffer += term_delete(sy);
  1193. }
  1194. if (lastreg != '_') {
  1195. registers[lastreg] = yank_buffer;
  1196. term_roll_yank();
  1197. }
  1198. } else if (term_vi_flag('y')) {
  1199. yank_buffer = '';
  1200. for (i = sy; i <= ey; i++) {
  1201. yank_buffer += _rtfl(sy) + "\n";
  1202. }
  1203. registers[lastreg] = yank_buffer;
  1204. term_roll_yank();
  1205. } else if (term_vi_flag('>')) {
  1206. for (i = sy; i <= ey; i++) {
  1207. term_indent(i,fa);
  1208. }
  1209. } else if (term_vi_flag('<')) {
  1210. for (i = sy; i <= ey; i++) {
  1211. term_unindent(i,fa);
  1212. }
  1213. }
  1214. }
  1215. if (term_vi_flag('d') || term_vi_flag('F') || term_vi_flag('c')) {
  1216. _term_update_printer();
  1217. }
  1218. if (term_vi_flag('d')) {
  1219. term_vi_unset('d');
  1220. lastcommand = 'd';
  1221. lastmotion = term_ex_motion;
  1222. restore = true;
  1223. }
  1224. if (term_vi_flag('y')) {
  1225. term_vi_unset('y');
  1226. restore = true;
  1227. }
  1228. if (term_vi_flag('F')) {
  1229. term_vi_unset('F');
  1230. restore = true;
  1231. }
  1232. lastaccum = accum;
  1233. if (restore) {
  1234. cursorx = sx - left;
  1235. if (cursorx < 0) {
  1236. cursorx = sx;
  1237. left = 0;
  1238. }
  1239. cursory = sy - base;
  1240. if (cursory < 0) {
  1241. cursory = sy;
  1242. base = 0;
  1243. }
  1244. term_scrollto();
  1245. }
  1246. if (term_vi_flag('c')) {
  1247. term_vi_unset('c');
  1248. term_setmode(1);
  1249. }
  1250. accum = 0;
  1251. }
  1252. function term_save_undo_line() {
  1253. if ((base+cursory) != undoy) {
  1254. undoy = base+cursory;
  1255. undoline = _rtfl(undoy);
  1256. }
  1257. }
  1258. function term_save_undo() {
  1259. undoset = term_freeze();
  1260. }
  1261. function term_delete(i) {
  1262. if (i > file.length) return '';
  1263. var j;
  1264. var z = file[i];
  1265. var g = tags[i];
  1266. for (j = i+1; j < file.length; j++) {
  1267. file[j-1] = file[j];
  1268. tags[j-1] = tags[j];
  1269. }
  1270. file=_pop(file);
  1271. return _rtf(z,g) + "\n";
  1272. }
  1273. function term_skipreverse2(re, fuzz) {
  1274. var y = cursory+base;
  1275. var x = (cursorx+left)+(1+fuzz);
  1276. for (;;) {
  1277. var t = file[y];
  1278. if (t == undefined) {
  1279. // beep
  1280. cursory = y - base;
  1281. return false;
  1282. }
  1283. if (fuzz) t += " "; else t = " " + t;
  1284. t = (t.substr(x, t.length-x));
  1285. var aa = re.exec(t);
  1286. if (!aa) {
  1287. y--;
  1288. x = 0;
  1289. } else {
  1290. x += _rel(re,t,aa).length;
  1291. cursorx = x - left;
  1292. cursory = y - base;
  1293. return true;
  1294. }
  1295. }
  1296. return false;
  1297. }
  1298. function term_skipforward(re, fuzz) {
  1299. var y = cursory+base;
  1300. var x = (cursorx+left)+(1+fuzz);
  1301. for (;;) {
  1302. var t = file[y];
  1303. if (t == undefined) {
  1304. // beep
  1305. cursory = y - base;
  1306. return false;
  1307. }
  1308. if (fuzz) t += " "; else t = " " + t;
  1309. t = (t.substr(x, t.length-x));
  1310. var aa = re.exec(t);
  1311. if (!aa) {
  1312. y++;
  1313. x = 0;
  1314. } else {
  1315. x += _rel(re,t,aa).length;
  1316. cursorx = x - left;
  1317. cursory = y - base;
  1318. return true;
  1319. }
  1320. }
  1321. return false;
  1322. }
  1323. function term_skipbackward(re) {
  1324. var y = cursory+base;
  1325. var x = (cursorx+left)+1;
  1326. for (;;) {
  1327. var t = file[y];
  1328. if (t == undefined) {
  1329. // beep
  1330. cursory = 0;
  1331. cursorx = 0;
  1332. return false;
  1333. }
  1334. t = " " + t.substr(0, x-1);
  1335. if (t == '') {
  1336. y--;
  1337. t = file[y];
  1338. if (t == undefined) continue;
  1339. x = (t.length);
  1340. continue;
  1341. }
  1342. var aa = re.exec(t);
  1343. if (!aa) {
  1344. left = 0;
  1345. cursorx = 0;
  1346. cursory = y - base;
  1347. return true;
  1348. } else {
  1349. x = _rel(re,t,aa).length;
  1350. cursorx = x - left;
  1351. cursory = y - base;
  1352. return true;
  1353. }
  1354. }
  1355. return false;
  1356. }
  1357. function term_search(s, top, start, bottom) {
  1358. var re = new RegExp(s.substr(1));
  1359. var i;
  1360. if (s.substr(0, 1) == '/') {
  1361. statustext='';
  1362. re.lastIndex = cursorx+left+1;
  1363. for (i = start; i < bottom; i++) {
  1364. var t = (file[i]);
  1365. if (i == start) {
  1366. t = t.substr(cursorx+left+1, t.length-(cursorx+left+1));
  1367. }
  1368. aa = re.exec(t);
  1369. if (!aa) continue;
  1370. var tx = _rel(re,t,aa).length;
  1371. if (i == start) {
  1372. tx += cursorx+left+1;
  1373. }
  1374. left = 0;
  1375. base = 0;
  1376. cursorx = tx;
  1377. cursory = i;
  1378. term_scrollto();
  1379. return true;
  1380. }
  1381. statustext = 'search hit BOTTOM, continuing at TOP';
  1382. for (i = top; i <= start; i++) {
  1383. var aa = re.exec(file[i]);
  1384. if (!aa) continue;
  1385. left = 0;
  1386. base = 0;
  1387. cursorx = _rel(re,file[i],aa).length;
  1388. cursory = i;
  1389. term_scrollto();
  1390. return true;
  1391. }
  1392. statustext = 'Pattern not found: ' + s.substr(1);
  1393. } else {
  1394. statustext='';
  1395. for (i = start; i >= top; i--) {
  1396. var t = file[i];
  1397. if (t == undefined) continue;
  1398. var tail = 0;
  1399. if (i == start) {
  1400. tail = (cursorx+left);
  1401. } else {
  1402. tail = t.length;
  1403. }
  1404. var right = tail;
  1405. while (tail > 0) {
  1406. tail--;
  1407. var xj = t.substr(tail, right-tail);
  1408. var aa = re.exec(xj);
  1409. if (!aa) continue;
  1410. var tx = tail+_rel(re,xj,aa).length;
  1411. left = 0;
  1412. base = 0;
  1413. cursorx = tx;
  1414. cursory = i;
  1415. term_scrollto();
  1416. return true;
  1417. }
  1418. }
  1419. statustext = 'search hit TOP, continuing at BOTTOM';
  1420. for (i = bottom; i >= start; i--) {
  1421. var t = file[i];
  1422. if (t == undefined) continue;
  1423. var tail = t.length;
  1424. while (tail > 0) {
  1425. tail--;
  1426. var xj = t.substr(tail, t.length-tail);
  1427. var aa = re.exec(xj);
  1428. if (!aa) continue;
  1429. cursorx = tail+_rel(re,xj,aa).length;
  1430. cursory = i;
  1431. left = 0;
  1432. base = 0;
  1433. term_scrollto();
  1434. return true;
  1435. }
  1436. }
  1437. statustext = 'Pattern not found: ' + s.substr(1);
  1438. }
  1439. return false;
  1440. }
  1441. function term_rsearch(s, top, start, bottom) {
  1442. var cx = s.substr(0, 1);
  1443. cx = (cx == '/') ? '?' : "/";
  1444. return term_search(cx+s.substr(1,s.length-1), top, start, bottom);
  1445. }
  1446. function _pop(q) {
  1447. var a = new Array();
  1448. var i;
  1449. for (i = 0; i < q.length-1; i++) {
  1450. a[i] = q[i];
  1451. }
  1452. return a;
  1453. }
  1454. function _addr(q) {
  1455. if (q == '.') {
  1456. return cursory+base;
  1457. }
  1458. if (q == '$') {
  1459. return file.length-1;
  1460. }
  1461. if (q.substr(0, 1) == "'") {
  1462. return marks[ q.substr(1, 1) ];
  1463. }
  1464. if (q == "\\/" || q == "\\&") {
  1465. var a=cursory;
  1466. var b=base;
  1467. term_search(lastsearch, 0, cursory+base, file.length);
  1468. var c=cursory+base;
  1469. cursory=a;
  1470. base=b;
  1471. return c;
  1472. }
  1473. if (q == "\\?") {
  1474. var a=cursory;
  1475. var b=base;
  1476. term_rsearch(lastsearch, 0, cursory+base, file.length);
  1477. var c=cursory+base;
  1478. cursory=a;
  1479. base=b;
  1480. return c;
  1481. }
  1482. if (q.substr(0, 1) == "/" || q.substr(0,1) == "?") {
  1483. var a=cursory;
  1484. var b=base;
  1485. term_search(q, 0, cursory+base, file.length);
  1486. var c=cursory+base;
  1487. cursory=a;
  1488. base=b;
  1489. return c;
  1490. }
  1491. q=parseInt(q)-1;
  1492. if (q >= file.length-1) q=file.length-1;
  1493. if (q < 0) q=0;
  1494. return q;
  1495. }
  1496. function term_command(s) {
  1497. var top, start,bottom;
  1498. if (s && s.length > 0 && s.substr(0,1) == ':') {
  1499. s = s.substr(1, s.length-1);
  1500. top = cursory+base;
  1501. start = top;
  1502. bottom = top;
  1503. } else {
  1504. top = 0;
  1505. start = cursory+base;
  1506. bottom = file.length;
  1507. }
  1508. // okay, this is kind of tricky
  1509. var i;
  1510. var tok = '';
  1511. var tc = 0;
  1512. var ng = new Array();
  1513. var lastre = undefined;
  1514. var nf = false;
  1515. /// xxx todo implement ! with nf
  1516. for (i = 0; i < s.length; i++) {
  1517. var c = s.substr(i, 1);
  1518. if ((tc==0 || tc==1) && "0123456789".indexOf(c) > -1) {
  1519. tc = 1;
  1520. tok = ''+tok+''+c;
  1521. continue;
  1522. } else if (tc == 1) {
  1523. tc = 0;
  1524. ng[ng.length] = parseInt(tok)-1;
  1525. tok = '';
  1526. }
  1527. if (c == '%') {
  1528. top = 0;
  1529. bottom = file.length;
  1530. start = cursory+base;
  1531. } else if (c == '!') {
  1532. nf = !nf;
  1533. } else if (c == ',') {
  1534. // do nothing
  1535. while (ng.length > 2) {
  1536. ng=_pop(ng);
  1537. }
  1538. } else if (c == ';') {
  1539. start = ng[ng.length-1];
  1540. ng = _pop(ng);
  1541. cursory=start;
  1542. base=0;
  1543. ng = _pop(ng);
  1544. } else if (c == '$') {
  1545. ng[ng.length] = file.length;
  1546. } else if (c == '.') {
  1547. ng[ng.length] = cursory+base;
  1548. } else if (c == "'") {
  1549. // mark
  1550. ng[ng.length] = marks[s.substr(i+1,1)];
  1551. i++;
  1552. } else if (c == "\\") {
  1553. i++;
  1554. c = s.substr(i, 1);
  1555. var qq;
  1556. if (c == '?') {
  1557. qq=term_rsearch;
  1558. } else {
  1559. qq=term_search;
  1560. }
  1561. if (ng.length == 1) {
  1562. top = ng[0];
  1563. ng = _pop(ng);
  1564. } else if (ng.length >= 2) {
  1565. top = ng[ng.length-2];
  1566. bottom = ng[ng.length-1];
  1567. ng = _pop(_pop(ng));
  1568. }
  1569. if (!qq(lastsearch,top,start,bottom)) {
  1570. return;
  1571. }
  1572. ng[ng.length] = cursory+base;
  1573. } else if (c == "/" || c == "?") {
  1574. var j = i;
  1575. for (i++; i < s.length; i++) {
  1576. var tc = s.substr(i, 1);
  1577. if (tc == "\\") i++;
  1578. else if (tc == c) break;
  1579. }
  1580. lastre = s.substr(j, i-j);
  1581. if (ng.length == 1) {
  1582. top = ng[0];
  1583. ng = _pop(ng);
  1584. } else if (ng.length >= 2) {
  1585. top = ng[ng.length-2];
  1586. bottom = ng[ng.length-1];
  1587. ng = _pop(_pop(ng));
  1588. }
  1589. if (!term_search(lastre,top,start,bottom)) {
  1590. return;
  1591. }
  1592. ng[ng.length] = cursory+base;
  1593. } else if (c == " " || c == "\t") {
  1594. continue;
  1595. } else {
  1596. break;
  1597. }
  1598. }
  1599. if (tc == 1) {
  1600. ng[ng.length] = parseInt(tok)-1;
  1601. tok = '';
  1602. i++;
  1603. }
  1604. if (ng.length == 1) {
  1605. top = ng[0];
  1606. bottom = ng[0];
  1607. } else if (ng.length >= 2) {
  1608. top = ng[ng.length-2];
  1609. bottom = ng[ng.length-1];
  1610. }
  1611. if (lastre != undefined) {
  1612. lastsearch = lastre;
  1613. registers["/"] = lastsearch.substr(1, lastsearch.length-1);
  1614. }
  1615. var cmd2 = s.substr(i,2);
  1616. var cmd = s.substr(i, 1);
  1617. if (cmd2 == 'wq' || cmd == 'x') {
  1618. editor_disable(true);
  1619. } else if (cmd == '=') {
  1620. statustext = '' + bottom;
  1621. return;
  1622. } else if (cmd2 == 'ha') {
  1623. window.print();
  1624. return;
  1625. } else if (cmd == 'w') {
  1626. var zx = term_freeze();
  1627. if (term._formelement) term._formelement.value=zx;
  1628. statustext = '"/tmp/mess4XbCXM" ' + file.length + 'L, '
  1629. + zx.length + 'C written';
  1630. } else if (!emacsen && s.substr(i,(s.length-i)) == 'emacs') {
  1631. statustext = 'EMACS mode enabled. Press M-x vi to use vi mode';
  1632. emacsen = true;
  1633. mode = 1;
  1634. } else if (emacsen && cmd2 == 'vi') {
  1635. statustext = 'VI mode enabled. Press ESC :emacs to use EMACS mode';
  1636. mode = 0;
  1637. emacsen = false;
  1638. } else if (cmd == 'e' && term._formelement) {
  1639. var zx = term_freeze();
  1640. if (cmd2 != 'e!') {
  1641. if (cmd2 == 'e?') {
  1642. if (!confirm("Your changes will be lost\nAre you sure?")) {
  1643. return;
  1644. }
  1645. } else if (term._formelement.value != zx) {
  1646. statustext = 'No write since last change (use ! to override)';
  1647. return;
  1648. }
  1649. }
  1650. term_thaw(term._formelement.value);
  1651. } else if (cmd == 'f') {
  1652. var zx = term_freeze();
  1653. statustext = '"/tmp/mess4XbCXM"';
  1654. if (term._formelement.value != zx) {
  1655. statustext += ' [Modified]';
  1656. }
  1657. statustext += ' line ' + (cursory+base+1) + ' of '
  1658. + file.length + ' col ' + (cursorx+left+1);
  1659. } else if (cmd == 'h' || s.substr(i,5) == 'about') {
  1660. statustext = "jsvi \xa9 2006 Internet Connection, Inc";
  1661. } else if (s.substr(i,4) == 'kwak') {
  1662. term.style.backgroundImage = 'url(ducky.jpg)';
  1663. statustext = 'kwak kwak kwak...';
  1664. } else if (s.substr(i,3) == 'moo') {
  1665. statustext = 'This editor does not have Super Cow Powers';
  1666. } else if (cmd == 'b') {
  1667. // only one buffer
  1668. } else if (cmd == 'n' || cmd == 'N') {
  1669. statustext = 'There is only one file to edit';
  1670. } else if (cmd == 'q') {
  1671. var zx = term_freeze();
  1672. if (cmd2 != 'q!') {
  1673. if (term._formelement.value != zx) {
  1674. if (cmd2 == 'q?') {
  1675. if (confirm("Your changes will be lost\nAre you sure?")) {
  1676. editor_disable(false);
  1677. return;
  1678. } else {
  1679. return;
  1680. }
  1681. }
  1682. statustext = 'No write since last change (use ! to override)';
  1683. return;
  1684. }
  1685. }
  1686. editor_disable(false);
  1687. } else if (cmd == 'd') {
  1688. // delete lines
  1689. yank_buffer = term_delete(top);
  1690. while (top < bottom) {
  1691. yank_buffer += term_delete(top);
  1692. bottom--;
  1693. }
  1694. if (lastreg != '_') {
  1695. registers[lastreg] = yank_buffer;
  1696. term_roll_yank();
  1697. }
  1698. term_scrollto();
  1699. } else if (cmd == 'u') {
  1700. var z = term_freeze();
  1701. term_thaw(undoset);
  1702. undoset = z;
  1703. } else if (cmd == 'y') {
  1704. yank_buffer = '';
  1705. for (i = top; i < bottom; i++) {
  1706. yank_buffer += (file[i])+"\n";
  1707. }
  1708. registers[lastreg] = yank_buffer;
  1709. term_roll_yank();
  1710. } else if (cmd == 'F') {
  1711. // styling!
  1712. var y;
  1713. var tadd = 0;
  1714. var tsub = 0;
  1715. var tset = undefined;
  1716. var otc = tagstyle;
  1717. var tg = '=';
  1718. for (y = i+1; y < s.length; y++) {
  1719. var cy = s.substr(y, 1);
  1720. if (cy == '=' || cy == '+' || cy == '-' || cy == '!') {
  1721. tg = cy;
  1722. } else {
  1723. var fl = 0;
  1724. if (cy == 'b') {
  1725. fl = 1;
  1726. } else if (cy == 'i') {
  1727. fl = 16;
  1728. } else if (cy == 'u') {
  1729. fl = 2;
  1730. } else if (cy == 'o') {
  1731. fl = 4;
  1732. } else {
  1733. statustext = 'Unrecognized formatting specifier: ' + cy;
  1734. return;
  1735. }
  1736. if (tg == '!') {
  1737. if (tset != undefined) tagstyle = tset;
  1738. tagstyle = tagstyle ^ fl;
  1739. } else if (tg == '=') {
  1740. if (tset == undefined) tset = 0;
  1741. tset = tset + fl;
  1742. } else if (tg == '+') {
  1743. tadd |= fl;
  1744. } else if (tg == '-') {
  1745. tsub |= fl;
  1746. }
  1747. }
  1748. }
  1749. if (tset == undefined) {
  1750. tagstyle = ((tagstyle | tadd) | tsub) ^ tsub;
  1751. } else {
  1752. tagstyle = tset;
  1753. }
  1754. // okay, we've set tagstyle
  1755. if (i != 0) {
  1756. // if this happened, then we were given a range(!)
  1757. for (y = top; y <= bottom; y++) {
  1758. if (file[y] == undefined) continue;
  1759. tags[y] = _mxs(file[y].length, tagstyle);
  1760. }
  1761. tagstyle = otc;
  1762. } else if (vselm) {
  1763. term_select();
  1764. term_vi_unset('d');
  1765. term_vi_unset('y');
  1766. term_vi_unset('c');
  1767. term_vi_set('F');
  1768. term_operate();
  1769. tagstyle = otc;
  1770. }
  1771. } else if (cmd == 'g' || cmd == 'v') {
  1772. // okay then
  1773. var y;
  1774. var ng = s.substr(i+1,(s.length-i)-1);
  1775. if (cmd == 'v') ng = '!' + ng;
  1776. for (y = 0; y < file.length; y++) {
  1777. base = 0;
  1778. cursory = y;
  1779. term_command(ng);
  1780. }
  1781. } else if (cmd == 't' || cmd2 == 'co') {
  1782. // copy- need address
  1783. var t = s.substr(i, s.length-i).replace(/^[a-z]*[ ]*/);
  1784. var x;
  1785. yank_buffer = "";
  1786. for (x = top; x <= bottom; x++) {
  1787. if (file[x] != undefined) {
  1788. yank_buffer += (file[x]) + "\n";
  1789. }
  1790. }
  1791. var a = cursory;
  1792. var b = base;
  1793. base = 0;
  1794. cursorx = 0;
  1795. left = 0;
  1796. cursory = _addr(t);
  1797. if (cursory < 0) cursory = 0;
  1798. term_paste(false, yank_buffer);
  1799. cursory = a;
  1800. base = b;
  1801. } else if (cmd == 'm') {
  1802. // move- need address
  1803. i++;
  1804. if (s.substr(i, 3) == 'ove') {
  1805. i += 3;
  1806. }
  1807. var t = s.substr(i, s.length-i);
  1808. yank_buffer = term_delete(top);
  1809. while (top < bottom) {
  1810. yank_buffer += term_delete(top);
  1811. bottom--;
  1812. }
  1813. var a = cursory;
  1814. var b = base;
  1815. base = 0;
  1816. cursorx = 0;
  1817. left = 0;
  1818. cursory = _addr(t);
  1819. if (cursory < 0) cursory = 0;
  1820. term_paste(false, yank_buffer);
  1821. cursory = a;
  1822. base = b;
  1823. } else if (cmd == 's') {
  1824. // substitute
  1825. i++;
  1826. // extract regex
  1827. var q = s.substr(i,1);
  1828. while (q == ' ') {
  1829. i++;
  1830. q = s.substr(i,1);
  1831. }
  1832. var sep = s.substr(i,1);
  1833. i++;
  1834. var lr, ls, lf;
  1835. if (sep == '') {
  1836. if (!lastsearch || !lastsubst) {
  1837. statustext = 'No previous substitute regular expression';
  1838. return;
  1839. }
  1840. lr = lastsearch.substr(1, lastsearch.length-1);
  1841. ls = lastsubst;
  1842. lf = lastflags;
  1843. } else {
  1844. var jj = i;
  1845. var zj;
  1846. for (; i < s.length; i++) {
  1847. zj = s.substr(i,1);
  1848. if (zj == "\\") {
  1849. i++;
  1850. } else if (zj == sep) {
  1851. break;
  1852. }
  1853. }
  1854. lastsearch = "/" + s.substr(jj, i-jj);
  1855. registers["/"] = lastsearch.substr(1, lastsearch.length-1);
  1856. i++; // sep
  1857. jj=i;
  1858. for (; i < s.length; i++) {
  1859. zj = s.substr(i,1);
  1860. if (zj == "\\") {
  1861. i++;
  1862. } else if (zj == sep) {
  1863. break;
  1864. }
  1865. }
  1866. lastsubst = s.substr(jj, i-jj);
  1867. lastflags = '';
  1868. i++;
  1869. var count = -1;
  1870. for (; i < s.length; i++) {
  1871. zj = s.substr(i,1);
  1872. if (zj == 'i' || zj == 'g') {
  1873. lastflags += zj;
  1874. } else {
  1875. count = parseInt(s.substr(i,s.length-i));
  1876. if (count > 0) {
  1877. break;
  1878. } else {
  1879. statustext = "Trailing characters";
  1880. return;
  1881. }
  1882. }
  1883. }
  1884. var re = new RegExp;
  1885. re.compile(lastsearch.substr(1, lastsearch.length-1),
  1886. (lastflags.indexOf('i') > -1) ? 'i' : '');
  1887. var hit = false;
  1888. for (i = top; i < bottom; i++) {
  1889. var t = file[i];
  1890. var g = tags[i];
  1891. var aa;
  1892. var st = t;
  1893. aa = re.exec(t);
  1894. if (!aa || aa.length == 0) continue;
  1895. file[i] = '';
  1896. tags[i] = '';
  1897. // okay got a hit, do this vi style
  1898. for (;;) {
  1899. t = _rer(re,st,aa);
  1900. var lt = _rel(re,st,aa);
  1901. var lg = _resubst(lastsubst,aa);
  1902. file[i] += lt + lg;
  1903. tags[i] += g.substr(0, lt.length) + _zeros(lg.length);
  1904. if (lastflags.indexOf('g') > -1) {
  1905. st = t;
  1906. aa = re.exec(t);
  1907. if (aa && aa.length > 0) continue;
  1908. }
  1909. file[i] += t;
  1910. tags[i] += g.substr(g.length - t.length, t.length);
  1911. break;
  1912. }
  1913. hit = true;
  1914. if (count > -1) {
  1915. count--;
  1916. if (count == 0) break;
  1917. }
  1918. }
  1919. if (!hit) {
  1920. statustext = 'Pattern not found: ' + lastsearch.substr(1, lastsearch.length-1);
  1921. }
  1922. }
  1923. } else if (cmd == '' && ng.length > 0) {
  1924. base = 0;
  1925. cursory = top;
  1926. } else {
  1927. statustext = "Not an editor command: " + s.substr(i,s.length-i);
  1928. }
  1929. }
  1930. function _resubst(s, aa) {
  1931. var i;
  1932. var out = '';
  1933. for (i = 0; i < s.length; i++) {
  1934. var zq = s.substr(i, 1);
  1935. if (zq == "\\") {
  1936. zq = s.substr(i, 2);
  1937. if (zq == "\\1") {
  1938. zq = aa[1];
  1939. } else if (zq == "\\2") {
  1940. zq = aa[2];
  1941. } else if (zq == "\\3") {
  1942. zq = aa[3];
  1943. } else if (zq == "\\4") {
  1944. zq = aa[4];
  1945. } else if (zq == "\\5") {
  1946. zq = aa[5];
  1947. } else if (zq == "\\6") {
  1948. zq = aa[6];
  1949. } else if (zq == "\\7") {
  1950. zq = aa[7];
  1951. } else if (zq == "\\8") {
  1952. zq = aa[8];
  1953. } else if (zq == "\\9") {
  1954. zq = aa[9];
  1955. } else {
  1956. zq = s.substr(i+1, 1);
  1957. }
  1958. i++;
  1959. } else if (zq == "&") {
  1960. zq = aa[0];
  1961. }
  1962. out += zq;
  1963. }
  1964. return out;
  1965. }
  1966. function _calcy(zx, x, g) {
  1967. if (zx && cursor._lasty != cursory) {
  1968. cursor._lasty = cursory;
  1969. var nh = 0;
  1970. while (zx && zx != document.body) {
  1971. nh += zx.offsetTop;
  1972. zx = zx.offsetParent;
  1973. }
  1974. cursor.style.top = nh + 'px';
  1975. }
  1976. var z = x.substr(cursorx, 1);
  1977. var q = g.substr(cursorx, 1).charCodeAt(0);
  1978. if (cursorx >= x.length || z == undefined || z == "\240" || z == '')
  1979. z = ' ';
  1980. if (cursor._lastch != z || cursor._lastgh != q) {
  1981. if (z == ' ') {
  1982. z = "\240";
  1983. q = 0;
  1984. }
  1985. while (cursor.firstChild)
  1986. cursor.removeChild(cursor.firstChild);
  1987. cursor.appendChild(document.createTextNode(z));
  1988. cursor._lastch = z;
  1989. cursor._lastgh = q;
  1990. if (q & 1) {
  1991. cursor.style.fontWeight = 'bold';
  1992. } else {
  1993. cursor.style.fontWeight = 'normal';
  1994. }
  1995. if (q & 2) {
  1996. cursor.style.textDecoration = 'underline';
  1997. } else {
  1998. cursor.style.textDecoration = 'none';
  1999. }
  2000. if (q & 16) {
  2001. cursor.style.fontStyle = 'italic';
  2002. } else {
  2003. cursor.style.fontStyle = 'normal';
  2004. }
  2005. }
  2006. }
  2007. function term_calcy() {
  2008. // fixup character inside... burrr
  2009. var xx = file[cursory+base];
  2010. var xg = tags[cursory+base];
  2011. var zleft = left;
  2012. if (cursory == (term_rows-1)) {
  2013. xx = command + " ";
  2014. zleft = commandleft;
  2015. xg = _mxs(xx.length+1,0);
  2016. }
  2017. var gg = term.childNodes;
  2018. if (gg.length > cursory) {
  2019. gg = term.childNodes[cursory];
  2020. } else {
  2021. gg = undefined;
  2022. }
  2023. _calcy(gg, xx.substr(zleft, xx.length-zleft), xg.substr(zleft, xg.length-zleft));
  2024. }
  2025. function term_calcx() {
  2026. if (cursorx != cursor._lastx) {
  2027. cursor.style.left = (cursorx * (term_cur_width)) + 'px';
  2028. cursor._lastx = cursorx;
  2029. term_calcy();
  2030. }
  2031. }
  2032. function term_scrollto() {
  2033. var h = term_rows;
  2034. var w = term_cols;
  2035. var x = cursorx+left;
  2036. var y = cursory+base;
  2037. var t = file[y];
  2038. if (command == '') h--;
  2039. var ex = parseInt((w/8));
  2040. if (ex < 4) ex = 4;
  2041. var ey = parseInt((h/8));
  2042. if (ey < 4) ey = 4;
  2043. while (t == undefined && y > 0) {
  2044. y--;
  2045. t = file[y];
  2046. }
  2047. if (t == undefined) t = '';
  2048. if (x >= t.length) {
  2049. if (mode) x = t.length;
  2050. else x = t.length-1;
  2051. }
  2052. if (x < 0) x = 0;
  2053. if (y < 0) y = 0;
  2054. if (x < left) {
  2055. left = (x - ex);
  2056. cursorx = ex;
  2057. if (left < 0) {
  2058. left = 0;
  2059. cursorx = 0;
  2060. }
  2061. } else if (x >= left+w) {
  2062. left = (x - w) + ex;
  2063. cursorx = w - ex;
  2064. } else {
  2065. cursorx = x - left;
  2066. }
  2067. if (y < base) {
  2068. base = (y - ey);
  2069. cursory = ey;
  2070. if (base < 0) {
  2071. base = 0;
  2072. cursory = 0;
  2073. }
  2074. } else if (y >= base+h) {
  2075. base = ((y - h) + ey);
  2076. cursory = (h - ey);
  2077. } else {
  2078. cursory = y - base;
  2079. }
  2080. term_calcx();
  2081. term_calcy();
  2082. }
  2083. function term_insert(y, str) {
  2084. var z = file.length;
  2085. file[z] = '';
  2086. tags[z] = '';
  2087. var i;
  2088. for (i = z; i > y; i--) {
  2089. file[i] = (file[i-1]);
  2090. tags[i] = (tags[i-1]);
  2091. }
  2092. file[y] = '';
  2093. tags[y] = '';
  2094. }
  2095. function term_paste(after, ign) {
  2096. if (ign != undefined) {
  2097. yank_buffer = ign;
  2098. } else {
  2099. registers['.'] = lastinsert;
  2100. registers[':'] = oldcommand;
  2101. registers['%'] = "/tmp/mess4XbCXM";
  2102. registers['#'] = "";
  2103. yank_buffer = registers[lastreg];
  2104. }
  2105. if (yank_buffer == undefined) return false;
  2106. if (yank_buffer.indexOf("\n") > -1) {
  2107. // insert after this line
  2108. if (after) cursory++;
  2109. var nq = yank_buffer.split("\n");
  2110. var nj;
  2111. for (nj = 0; nj < nq.length; nj++) {
  2112. if (nj == (nq.length-1)) {
  2113. if (nq[nj] == undefined) break;
  2114. if (nq[nj] == '') break;
  2115. // handled specially
  2116. var aa = _hra(nq[nj]);
  2117. file[cursory+base+nj] = aa[0] + (file[cursory+base+nj]);
  2118. tags[cursory+base+nj] = aa[1] + (tags[cursory+base+nj]);
  2119. break;
  2120. }
  2121. term_insert(cursory+base+nj);
  2122. var aa = _hra(nq[nj]);
  2123. file[cursory+base+nj] = aa[0];
  2124. tags[cursory+base+nj] = aa[1];
  2125. }
  2126. } else {
  2127. var t = (file[cursory+base]);
  2128. var g = (tags[cursory+base]);
  2129. var aa = _hra(yank_buffer);
  2130. if (after) cursorx++;
  2131. file[cursory+base] = t.substr(0, cursorx+left)
  2132. + aa[0] + t.substr(cursorx+left, t.length-(cursorx+left));
  2133. tags[cursory+base] = g.substr(0, cursorx+left)
  2134. + aa[1] + g.substr(cursorx+left, g.length-(cursorx+left));
  2135. }
  2136. return true;
  2137. }
  2138. function term_keyfix(e) {
  2139. if (!e) e = window.event;
  2140. var ch = e.keyCode;
  2141. if (!ch) ch = e.which;
  2142. if (e.DOM_VK_UP) {
  2143. if (e.DOM_VK_UP == ch) ch = 57373;
  2144. else if (e.DOM_VK_DOWN == ch) ch = 57374;
  2145. else if (e.DOM_VK_LEFT == ch) ch = 57375;
  2146. else if (e.DOM_VK_RIGHT == ch) ch = 57376;
  2147. }
  2148. if (ch == 8 || ch == 9 || ch == 37 || ch == 39
  2149. || ch == 38 || ch == 40 || ch == 127
  2150. || ch == 33 || ch == 34 || ch == 36
  2151. || ch == 35 || ch == 45 || ch == 46
  2152. || ch == 57373
  2153. || ch == 57374
  2154. || ch == 57375
  2155. || ch == 57376) {
  2156. if (e.preventDefault) e.preventDefault();
  2157. if (e.stopPropagation) e.stopPropagation();
  2158. term_keypress_inner(e, true);
  2159. e.cancelBubble=true;
  2160. return false;
  2161. } else {
  2162. e.cancelBubble=false;
  2163. return true;
  2164. }
  2165. }
  2166. function term_keypress(e) {
  2167. if (!e) e = window.event;
  2168. if (e.preventDefault) e.preventDefault();
  2169. if (e.stopPropagation) e.stopPropagation();
  2170. if (suggest._visible) {
  2171. suggest.style.display = 'none';
  2172. suggest._visible = false;
  2173. }
  2174. e.cancelBubble=true;
  2175. term_keypress_inner(e, false);
  2176. return false;
  2177. }
  2178. function term_keypress_inner(e, synth) {
  2179. var k = e.which;
  2180. var kc;
  2181. if (e.charCode) {
  2182. if (e.charCode == 27 || e.charCode == 13 || e.charCode == 10
  2183. || e.charCode == 8
  2184. || e.charCode == 9) {
  2185. k = e.charCode;
  2186. kc = String.fromCharCode(e.charCode);
  2187. } else if (e.charCode == 63232) {
  2188. k = 57373;
  2189. } else if (e.charCode == 63233) {
  2190. k = 57374;
  2191. } else if (e.charCode == 63234) {
  2192. k = 57375;
  2193. } else if (e.charCode == 63235) {
  2194. k = 57376;
  2195. } else {
  2196. if (e.charCode == 191) return; // wtf?
  2197. kc = String.fromCharCode(e.charCode);
  2198. k = 0;
  2199. }
  2200. } else if (e.keyCode) {
  2201. k = e.keyCode;
  2202. if (e.DOM_VK_UP) {
  2203. if (e.DOM_VK_UP == k) k = 57373;
  2204. else if (e.DOM_VK_DOWN == k) k = 57374;
  2205. else if (e.DOM_VK_LEFT == k) k = 57375;
  2206. else if (e.DOM_VK_RIGHT == k) k = 57376;
  2207. } else {
  2208. kc = String.fromCharCode(e.keyCode);
  2209. }
  2210. if (k == 191) return; // unicode i think
  2211. } else {
  2212. if (!k || k == 191) return;
  2213. kc = String.fromCharCode(k);
  2214. var i;
  2215. }
  2216. var mod;
  2217. if (e.modifiers) mod = e.modifiers; else mod = 0;
  2218. var ctrl = e.ctrlKey | (mod & 2);
  2219. var shift = e.shiftKey | (mod & 4);
  2220. var meta = e.altKey | e.metaKey | (mod &

Large files files are truncated, but you can click here to view the full file