|
104 | 104 | editor.selection.setRange({start, end})
|
105 | 105 |
|
106 | 106 | editor.renderer.scrollCursorIntoView(null, 0.5)
|
| 107 | + |
| 108 | + lastRe = eqreg |
| 109 | + |
| 110 | + return !match.fake; |
| 111 | +} |
107 | 112 |
|
| 113 | +function updateSearch(eqreg) { |
| 114 | + if (!eqreg) eqreg = lastRe |
108 | 115 | if (searchValue != eqreg.source) {
|
109 | 116 | searchValue = eqreg.source
|
110 | 117 | }
|
|
113 | 120 | editor.searchBox.searchInput.value = eqreg.source
|
114 | 121 | editor.searchBox.regExpOption.checked = true;
|
115 | 122 | editor.searchBox.$syncOptions()
|
116 |
| - }) |
117 |
| - |
118 |
| - return !match.fake; |
| 123 | + }) |
119 | 124 | }
|
120 |
| - |
| 125 | +var lastRe |
121 | 126 | var searchValue
|
122 | 127 | var searchTimeout
|
123 | 128 |
|
|
210 | 215 |
|
211 | 216 | initialize()
|
212 | 217 | }}, "initialize"],
|
213 |
| - // " ", |
| 218 | + |
214 | 219 |
|
215 |
| - // ["button", { |
216 |
| - // style: "float: right", |
217 |
| - // onclick: function() { |
218 |
| - // sidePanel.remove() |
219 |
| - // editor.focus() |
220 |
| - // } |
221 |
| - // }, "x"], |
222 |
| - ["hr"], |
| 220 | + ["hr"], // bibliography |
| 221 | + ["button", {onclick: function() { |
| 222 | + bookCitation(); |
| 223 | + editor.renderer.scrollCursorIntoView(null, 0.5) |
| 224 | + |
| 225 | + editor.focus() |
| 226 | + }}, "cite"], |
| 227 | + |
| 228 | + |
| 229 | + ["button", {onclick: function() { |
| 230 | + findNext(/\[[\d\,\-\s]*\]/g, eqAndBibExclusionRe) |
| 231 | + updateSearch() |
| 232 | + editor.focus() |
| 233 | + }}, "next"], |
| 234 | + |
| 235 | + " \x1a \x1a \x1a ", |
| 236 | + |
| 237 | + ["button", {onclick: function() { |
| 238 | + editor.selection.moveTo(0, 0) |
| 239 | + var max = 10000 |
| 240 | + while(findNext(/\[[\d\,\-\s]*\]/g, eqAndBibExclusionRe) && max-- >0) { |
| 241 | + bookCitation(); |
| 242 | + } |
| 243 | + editor.focus() |
| 244 | + }}, "all"], |
| 245 | + |
| 246 | + ["br"], |
| 247 | + |
| 248 | + ["button", {onclick: function() { |
| 249 | + |
| 250 | + var text = editor.getSelectedText() |
| 251 | + |
| 252 | + text = text |
| 253 | + .replace(/^\s*(References|Literature|литература)/i, "") |
| 254 | + .replace(/\n+(\d+)\.?/gm, function(_, number) { |
| 255 | + return "\n\n\\bibitem{book" + number +"}\n" |
| 256 | + }); |
| 257 | + |
| 258 | + var replacement = "\\begin{thebibliography}{1}\n" |
| 259 | + + text |
| 260 | + + "\n\\end{thebibliography}" |
| 261 | + |
| 262 | + editor.insert(replacement) |
| 263 | + editor.focus() |
| 264 | + }}, "bibliography"], |
| 265 | + |
| 266 | + |
| 267 | + |
| 268 | + ["hr"], // section |
223 | 269 | ["button", {onclick: function() {
|
224 | 270 |
|
225 | 271 | var line = editor.getSelectedText()
|
|
230 | 276 |
|
231 | 277 | editor.insert(`\\section{ ${caption} }\n`+`\\label{part${number}}\n`)
|
232 | 278 | editor.renderer.scrollCursorIntoView(null, 0.5)
|
233 |
| - editor.focus() |
| 279 | + editor.focus() |
234 | 280 |
|
235 | 281 | // findNext(sectionReg)
|
236 | 282 | }}, "section"],
|
237 | 283 | ["button", {onclick: function() {
|
238 | 284 | findNext(sectionReg, eqAndBibExclusionRe)
|
| 285 | + updateSearch() |
239 | 286 | editor.focus()
|
240 | 287 | }}, "next"],
|
241 | 288 |
|
|
255 | 302 |
|
256 | 303 | ["button", {onclick: function() {
|
257 | 304 | findNext(eqReg)
|
| 305 | + updateSearch() |
258 | 306 | editor.focus()
|
259 | 307 | }}, "next"],
|
260 | 308 | " ",
|
|
284 | 332 | ["button", {onclick: function() {
|
285 | 333 | findNext(inlineEqReg)
|
286 | 334 | editor.focus()
|
| 335 | + updateSearch() |
287 | 336 | }}, "next"],
|
288 | 337 | ["br"],
|
289 | 338 |
|
|
335 | 384 | ["button", {onclick: function() {
|
336 | 385 | findNext(eqRefReg, eqAndBibExclusionRe)
|
337 | 386 | editor.focus()
|
| 387 | + updateSearch() |
338 | 388 | }}, "next"],
|
339 | 389 | " \x1b \x1b \x1b \x1b ",
|
340 | 390 |
|
|
440 | 490 | // (\\begin{tabular[\s\S]*?\\end{tabular})
|
441 | 491 | findNext(/(TAB(LE)|Таблица)?\s*([\d.]+)([\S\s]*?)/gi)
|
442 | 492 | editor.focus()
|
| 493 | + updateSearch() |
443 | 494 | }}, "next"],
|
444 | 495 | ["br"],
|
445 | 496 |
|
|
491 | 542 | ["button", {onclick: function() {
|
492 | 543 | findNext(/(FIG(URES?|\.)?|TABLES?)\s*[\d\.]+[a-z]?(?:\s*(?:and|-|,)\s*([\d\.]+[a-z]?))?/ig)
|
493 | 544 | editor.focus()
|
| 545 | + updateSearch() |
494 | 546 | }}, "next"],
|
495 | 547 | ["span", "\xa0\xa0\xa0\xa0\xa0\xa0"],
|
496 | 548 | ["button", {onclick: function() {
|
|
520 | 572 | editor.focus()
|
521 | 573 | }}, "ref"],
|
522 | 574 |
|
| 575 | + |
523 | 576 | ["hr"],
|
524 | 577 | ["button", {onclick: function() {
|
525 |
| - bookCitation(); |
526 |
| - editor.renderer.scrollCursorIntoView(null, 0.5) |
527 |
| - |
528 |
| - editor.focus() |
529 |
| - }}, "cite"], |
| 578 | + var text = editor |
530 | 579 |
|
531 | 580 |
|
532 |
| - ["button", {onclick: function() { |
533 |
| - findNext(/\[[\d\,\-\s]*\]/g, eqAndBibExclusionRe) |
534 |
| - editor.focus() |
535 |
| - }}, "next"], |
| 581 | + |
| 582 | + var line = editor.getSelectedText() |
| 583 | + expRe.lastIndex=0 |
| 584 | + var m = expRe.exec(line) |
| 585 | + console.log(m) |
| 586 | + var contents = (m[1] || m[2]) |
| 587 | + if (!contents) return; |
536 | 588 |
|
537 |
| - " \x1a \x1a \x1a ", |
| 589 | + var replacement = "e^{" + contents + "}" |
538 | 590 |
|
539 |
| - ["button", {onclick: function() { |
540 |
| - editor.selection.moveTo(0, 0) |
541 |
| - var max = 10000 |
542 |
| - while(findNext(/\[[\d\,\-\s]*\]/g, eqAndBibExclusionRe) && max-- >0) { |
543 |
| - bookCitation(); |
544 |
| - } |
545 |
| - editor.focus() |
546 |
| - }}, "all"], |
| 591 | + var sel = editor.selection.toJSON(); |
547 | 592 |
|
548 |
| - ["br"], |
| 593 | + var reg = ace.require("ace/lib/lang").escapeRegExp(line); |
| 594 | + var reg = new RegExp(reg) |
549 | 595 |
|
550 |
| - // ["button", {onclick: function() { |
551 |
| - // replaceBibItem() |
552 |
| - // editor.renderer.scrollCursorIntoView(null, 0.5) |
| 596 | + editor.selection.moveTo(0, 0) |
| 597 | + var max = 10000 |
| 598 | + var data = {} |
| 599 | + while(findNext(reg) && max-- >0) { |
| 600 | + editor.insert(replacement) |
| 601 | + } |
553 | 602 |
|
554 |
| - // editor.focus() |
555 |
| - // }}, "bibitem"], |
556 |
| - |
557 |
| - // ["button", {onclick: function() { |
558 |
| - // findNext(/\n+\d+\./gm, /^[\S\s]*\\begin{thebibliography}/g) |
559 |
| - // editor.focus() |
560 |
| - // }}, "next"], |
561 |
| - // " \xa0 \xa0 \xa0 \xa0 \xa0 \xa0 ", |
562 |
| - // ["button", {onclick: function() { |
563 |
| - // while (findNext(/\n+\d+\./gm, /^[\S\s]*\\begin{thebibliography}/g)) { |
564 |
| - // replaceBibItem(); |
565 |
| - // } |
566 |
| - // findNext(/n{thebibliography}/) |
567 |
| - // editor.focus(); |
568 |
| - // }}, "all"], |
| 603 | + editor.selection.fromJSON(sel); |
| 604 | + // sectionReg.lastIndex = 0 |
| 605 | + // var match = sectionReg.exec(line) |
| 606 | + // var number = match[1] |
| 607 | + // var caption = match[2].trim() |
569 | 608 |
|
570 |
| - ["button", {onclick: function() { |
| 609 | + // editor.insert(`\\section{ ${caption} }\n`+`\\label{part${number}}\n`) |
| 610 | + editor.renderer.scrollCursorIntoView(null, 0.5) |
571 | 611 |
|
572 |
| - var text = editor.getSelectedText() |
573 |
| - |
574 |
| - text = text |
575 |
| - .replace(/^\s*(References|Literature|литература)/i, "") |
576 |
| - .replace(/\n+(\d+)\.?/gm, function(_, number) { |
577 |
| - return "\n\n\\bibitem{book" + number +"}\n" |
578 |
| - }); |
| 612 | + editor.focus() |
579 | 613 |
|
580 |
| - var replacement = "\\begin{thebibliography}{1}\n" |
581 |
| - + text |
582 |
| - + "\n\\end{thebibliography}" |
| 614 | + }}, "exp to e"], |
583 | 615 |
|
584 |
| - editor.insert(replacement) |
| 616 | + ["button", {onclick: function() { |
| 617 | + findNext(expRe) |
585 | 618 | editor.focus()
|
586 |
| - }}, "bibliography"], |
587 |
| - |
588 |
| - ["hr"], |
| 619 | + updateSearch() |
| 620 | + }}, "next"], |
| 621 | + |
589 | 622 |
|
590 | 623 | ], sidePanel)
|
591 | 624 |
|
| 625 | +var expRe = /\\exp\s*(?:\(([^)]*)\)|\\left\(([^)]*)\\right\))/g |
| 626 | + |
| 627 | + |
592 | 628 | function replaceBibItem() {
|
593 | 629 | var line = editor.getSelectedText()
|
594 | 630 | var replacement = line.replace(/\n+(\d+)\.?/gm, function(_, number) {
|
|
693 | 729 | return `\\eqref{eq${e1}}`
|
694 | 730 | })
|
695 | 731 | if (v1 != v) editor.setValue(v1)
|
696 |
| - |
697 | 732 | }
|
698 | 733 |
|
699 | 734 | function fixBibliography() {
|
|
711 | 746 | editor.setValue(newValue)
|
712 | 747 | }
|
713 | 748 |
|
714 |
| - |
| 749 | +function randomStuff() { |
715 | 750 |
|
716 | 751 | value = "\\bibitem{book19}\n\
|
717 | 752 | Uflyand, Ya.1968. Integral Transformations in Problems of the Elasticity Theory. Leningrad. Nauka. 402 (in Russian). \
|
|
738 | 773 | return intro + newNames + " (" + number + ") "
|
739 | 774 |
|
740 | 775 | })
|
| 776 | +} |
741 | 777 |
|
| 778 | +function removeAlignement() { |
| 779 | + v=editor.getValue().replace(/\\(begin|end){aligned}/g, "") |
| 780 | + .replaceAll("\\right.", "").replaceAll("\\left.", "") |
| 781 | + .replaceAll("\\right", "").replaceAll("\\left", "") |
| 782 | + |
| 783 | + .replaceAll(/\\\\/g, "") .replaceAll(/&/g, "") |
| 784 | + .replaceAll(/\\\\/g, "") .replaceAll(/&/g, "") |
| 785 | + .replaceAll(/ *\+ *\n *\+/g, " +\n") |
| 786 | + .replaceAll(/ *\- *\n *\-/g, " -\n") |
| 787 | + .replaceAll(/ *\\times *\n *\\times/g, " \\times\n") |
| 788 | + console.log(v) |
| 789 | + |
| 790 | +} |
742 | 791 |
|
743 | 792 | window.onpagehide = function() {
|
744 | 793 | localStorage.lastValue = editor.getValue();
|
|
0 commit comments