forked from chrisgrieser/obsidian-smarter-md-hotkeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
665 lines (564 loc) · 22.5 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
import * as constant from "const";
import { Editor, EditorPosition, EditorSelection, Notice, Plugin, requireApiVersion } from "obsidian";
declare module "obsidian" {
// add type safety for the undocumented methods
interface Editor {
cm: {
findWordAt?: (pos: EditorPosition) => EditorSelection;
state?: { wordAt: (offset: number) => { from: number, to: number} };
};
}
interface App {
commands: { executeCommandById: (commandID: string) => void };
}
interface Vault {
setConfig: (config: string, newValue: boolean) => void;
getConfig: (config: string) => boolean;
}
}
// needed for Chinese Word Delimiter Fix https://github.com/chrisgrieser/obsidian-smarter-md-hotkeys/pull/30
const posEqual = (a: EditorPosition, b: EditorPosition) => a.line === b.line && a.ch === b.ch;
const rangeEqual = (a: EditorSelection, b: EditorSelection) => posEqual(a.anchor, b.anchor) && posEqual(a.head, b.head);
export default class SmarterMDhotkeys extends Plugin {
async onload() {
constant.MD_COMMANDS.forEach((command) => {
const { id, name, before, after } = command;
this.addCommand({
id,
name,
editorCallback: (editor) => this.expandAndWrap(before, after, editor),
});
});
constant.OTHER_COMMANDS.forEach((command) => {
const { id, name } = command;
this.addCommand({
id,
name,
editorCallback: (editor) => this.otherCommands(id, editor),
});
});
console.log("Smarter MD Hotkeys loaded.");
}
async onunload() { console.log("Smarter MD Hotkeys unloaded.") }
async otherCommands (commandID: string, editor: Editor) {
const activeFile = this.app.workspace.getActiveFile();
if (!activeFile) return; // no file open
// File Deletion
if (commandID === "smarter-delete-current-file") {
const runCommand = (str: string) => this.app.commands.executeCommandById(str);
const deletionPromptEnabled = this.app.vault.getConfig("promptDelete");
if (deletionPromptEnabled) {
new Notice ("This command requires that the core Obsidian setting \"Confirm file deletion\" is *disabled*.");
return; // the quite simple method below only works the prompt is disabled.
}
runCommand("app:delete-file");
runCommand("app:go-back");
runCommand("app:go-back");
new Notice ("\"" + activeFile.name + "\" deleted.");
// Copy Path
} else if (commandID === "smarter-copy-path") {
let noticeText;
const relativePath = activeFile.path;
// @ts-ignore, basePath not part of API
const absolutePath = this.app.vault.adapter.basePath + "/" + relativePath;
let parentFolder;
if (relativePath.includes("/")) parentFolder = relativePath.replace(/(.*)\/.*/, "$1");
else parentFolder = "/"; // root
const currentClipboardText = await navigator.clipboard.readText();
if (currentClipboardText === relativePath) {
await navigator.clipboard.writeText(absolutePath);
noticeText = "Absolute path copied: \n" + absolutePath;
} else if (currentClipboardText === absolutePath) {
await navigator.clipboard.writeText(parentFolder);
noticeText = "Parent Folder copied: \n" + parentFolder;
} else {
await navigator.clipboard.writeText(relativePath);
noticeText = "Relative path copied: \n" + relativePath;
}
// slightly longer Notice so a longer path can be read
new Notice(noticeText, 7000); // eslint-disable-line no-magic-numbers
// Copy File Name
} else if (commandID === "smarter-copy-file-name") {
const currentClipboardText = await navigator.clipboard.readText();
let fileName = activeFile.basename;
if (currentClipboardText === fileName) fileName += "." + activeFile.extension;
await navigator.clipboard.writeText(fileName);
new Notice("File Name copied: \n" + fileName);
// Toggle Line Numbers
} else if (commandID === "toggle-line-numbers") {
const optionEnabled = this.app.vault.getConfig("showLineNumber");
this.app.vault.setConfig("showLineNumber", !optionEnabled);
// Toggle Readable Line Length
} else if (commandID === "toggle-readable-line-length") {
const optionEnabled = this.app.vault.getConfig("readableLineLength");
this.app.vault.setConfig("readableLineLength", !optionEnabled);
// Follow Link
} else if (commandID === "smarter-follow-link") {
const cursor = editor.getCursor("from");
const line = editor.getLine(cursor.line);
const selection = editor.getSelection();
const text = selection || line;
const links = [...text.matchAll(constant.LINK_REGEX)];
switch (links.length) {
case 0:
return;
case 1: {
// Follow link if there is only a single link in the given line
const [link] = links;
const [
/* fullMatch */,
directURL,
markdownLink,
internalLink
] = link || [];
const externalLink = markdownLink || directURL;
if (internalLink)
this.app.workspace.openLinkText(internalLink, activeFile.path);
if (externalLink)
open(externalLink);
return;
}
default: {
for (const link of links) {
const [
fullMatch,
directURL,
markdownLink,
internalLink
] = link || [];
const externalLink = markdownLink || directURL;
const isCursorOnMarkup =
cursor.ch >= link.index && cursor.ch <= link.index + fullMatch.length;
// Open all external links when visually selected
if (selection && externalLink)
open(externalLink);
// Follow link if directly under the cursor
else if (isCursorOnMarkup) {
if (externalLink)
open(externalLink);
if (internalLink) {
this.app.workspace.openLinkText(
internalLink,
activeFile.path
);
}
return;
}
}
}
}
// Hide Notice
} else if (commandID === "hide-notice") {
const isVersionFifteen = requireApiVersion("0.15.0");
if (isVersionFifteen) {
// @ts-ignore
for (const el of activeDocument.body.getElementsByClassName("notice")) el.hide();
} else {
// @ts-ignore
for (const el of document.body.getElementsByClassName("notice"))el.hide();
}
}
}
async expandAndWrap(frontMarkup: string, endMarkup: string, editor: Editor) {
interface contentChange {
line: number;
shift: number;
}
// Utility Functions TODO: export these to an `utils.ts`
//-------------------------------------------------------------------
const startOffset = () => editor.posToOffset(editor.getCursor("from"));
const endOffset = () => editor.posToOffset(editor.getCursor("to"));
const noteLength = () => editor.getValue().length;
const offToPos = (offset: number) => {
// prevent error when at the start or beginning of document
if (offset < 0) offset = 0;
if (offset > noteLength()) offset = noteLength();
return editor.offsetToPos(offset);
};
function isOutsideSel (bef:string, aft:string) {
const so = startOffset();
const eo = endOffset();
if (so - bef.length < 0) return false; // beginning of the document
if (eo - aft.length > noteLength()) return false; // end of the document
const charsBefore = editor.getRange(offToPos(so - bef.length), offToPos(so));
const charsAfter = editor.getRange(offToPos(eo), offToPos(eo + aft.length));
return charsBefore === bef && charsAfter === aft;
}
const isMultiLineMarkup = () => ["`", "%%", "<!--", "$"].includes(frontMarkup);
const markupOutsideSel = () => isOutsideSel (frontMarkup, endMarkup);
function markupOutsideMultiline (anchor: EditorPosition, head: EditorPosition) {
if (anchor.line === 0) return false;
if (head.line === editor.lastLine()) return false;
const prevLineContent = editor.getLine(anchor.line - 1);
const followLineContent = editor.getLine(head.line + 1);
return prevLineContent.startsWith(frontMarkup) && followLineContent.startsWith(endMarkup);
}
const noSel = () => !editor.somethingSelected();
const multiLineSel = () => editor.getSelection().includes("\n");
function deleteLine (lineNo: number) {
// there is no 'next line' when cursor is on the last line
if (lineNo < editor.lastLine()) {
const lineStart = { line: lineNo, ch: 0 };
const nextLineStart = { line: lineNo + 1, ch: 0 };
editor.replaceRange("", lineStart, nextLineStart);
} else {
const previousLineEnd = { line: lineNo - 1, ch: editor.getLine(lineNo).length };
const lineEnd = { line: lineNo, ch: editor.getLine(lineNo).length };
editor.replaceRange("", previousLineEnd, lineEnd);
}
}
function log (msg: string, appendSelection?: boolean) {
if (!constant.DEBUGGING) return;
let appended = "";
if (appendSelection) appended = ": \"" + editor.getSelection() + "\"";
if (!msg.startsWith("\n")) msg = "- " + msg;
console.log(msg + appended);
}
// Core Functions
//-------------------------------------------------------------------
function textUnderCursor (ep: EditorPosition) {
// prevent underscores (wrongly counted as words) to be expanded to
if (markupOutsideSel() && noSel()) return { anchor: ep, head: ep };
let endPos, startPos;
if (frontMarkup !== "`") {
// https://codemirror.net/doc/manual.html#api_selection
// https://codemirror.net/6/docs/ref/#state
// https://github.com/argenos/nldates-obsidian/blob/e6b95969d7215b9ded2b72c4e319e35bc6022199/src/utils.ts#L16
// https://github.com/obsidianmd/obsidian-api/blob/fac5e67f5d83829a4e0126905494c8cbca27765b/obsidian.d.ts#L787
// TODO: update for mobile https://github.com/obsidianmd/obsidian-releases/pull/712#issuecomment-1004417481
if (editor.cm instanceof window.CodeMirror) return editor.cm.findWordAt(ep); // CM5
const word = editor.cm.state.wordAt(editor.posToOffset (ep)); // CM6
if (!word) return { anchor: ep, head: ep }; // for when there is no word close by
startPos = offToPos(word.from);
endPos = offToPos(word.to);
}
// Inline-Code: use only space as delimiter
if (frontMarkup === "`" || frontMarkup === "$") {
log ("Getting Code under Cursor");
const so = editor.posToOffset(ep);
let charAfter, charBefore;
let [i, j, endReached, startReached] = [0, 0, false, false];
while (!/\s/.test(charBefore) && !startReached) {
charBefore = editor.getRange(offToPos(so - (i+1)), offToPos(so - i));
i++;
if (so-(i-1) === 0) startReached = true;
}
while (!/\s/.test(charAfter) && !endReached) {
charAfter = editor.getRange(offToPos(so + j), offToPos(so + j+1));
j++;
if (so+(j-1) === noteLength()) endReached = true;
}
startPos = offToPos(so - (i-1));
endPos = offToPos(so + (j-1));
}
return { anchor: startPos, head: endPos };
}
function trimSelection() {
let trimAfter = constant.TRIMAFTER;
let trimBefore = constant.TRIMBEFORE;
// modify what to trim based on command
if (isMultiLineMarkup()) {
trimBefore = [frontMarkup];
trimAfter = [endMarkup];
} else if (endMarkup) { // check needed to ensure no special commands are added
trimBefore.push(frontMarkup);
trimAfter.push(endMarkup);
}
let selection = editor.getSelection();
let so = startOffset();
log ("before trim", true);
// before
let trimFinished = false;
while (!trimFinished) {
let cleanCount = 0;
trimBefore.forEach(str => {
if (selection.startsWith(str)) {
selection = selection.slice(str.length);
so += str.length;
}
else cleanCount++;
});
if (cleanCount === trimBefore.length || !selection.length) trimFinished = true;
}
// after
trimFinished = false;
while (!trimFinished) {
let cleanCount = 0;
trimAfter.forEach((str) => {
if (selection.endsWith(str)) selection = selection.slice(0, -str.length);
else cleanCount++;
});
if (cleanCount === trimAfter.length || !selection.length) trimFinished = true;
}
// block-ID
const blockID = selection.match(/ \^\w+$/);
if (blockID) selection = selection.slice(0, -blockID[0].length);
editor.setSelection(offToPos(so), offToPos(so + selection.length));
log ("after trim", true);
}
function expandSelection () {
trimSelection();
log ("before expandSelection", true);
// expand to word
const preSelExpAnchor = editor.getCursor("from");
const preSelExpHead = editor.getCursor("to");
const firstWordRange = textUnderCursor(preSelExpAnchor);
let lastWordRange = textUnderCursor(preSelExpHead);
// Chinese Word Delimiter Fix https://github.com/chrisgrieser/obsidian-smarter-md-hotkeys/pull/30
if (!posEqual(preSelExpAnchor, preSelExpHead) && preSelExpHead.ch > 0 ) {
const lastWordRangeInner = textUnderCursor({
...preSelExpHead,
ch: preSelExpHead.ch - 1,
});
// if the result of last word range is not the same as the result of
// head going back one character, use the inner result
if (!rangeEqual(lastWordRange, lastWordRangeInner)) lastWordRange = lastWordRangeInner;
}
editor.setSelection(firstWordRange.anchor, lastWordRange.head);
log ("after expandSelection", true);
trimSelection();
// has to come after trimming to include things like brackets
const expandWhenOutside = constant.EXPANDWHENOUTSIDE;
expandWhenOutside.forEach(pair => {
if (pair[0] === frontMarkup || pair[1] === endMarkup ) return; // allow undoing of the command creating the syntax
const trimLastSpace = Boolean(pair[2]);
if (isOutsideSel (pair[0], pair[1])) {
firstWordRange.anchor.ch -= pair[0].length;
lastWordRange.head.ch += pair[1].length;
if (trimLastSpace) lastWordRange.head.ch--; // to avoid conflicts between trimming and expansion
editor.setSelection(firstWordRange.anchor, lastWordRange.head);
}
});
return { anchor: preSelExpAnchor, head: preSelExpHead };
}
function recalibratePos (pos: EditorPosition) {
contentChangeList.forEach (change => {
if (pos.line === change.line) pos.ch += change.shift;
});
return pos;
}
function applyMarkup (preAnchor: EditorPosition, preHead: EditorPosition, lineMode: string ) {
let selectedText = editor.getSelection();
const so = startOffset();
let eo = endOffset();
// abort if empty line & multi, since no markup on empty line in between desired
if (noSel() && lineMode === "multi") return;
// Do Markup
if (!markupOutsideSel()) {
// insert extra space for comments
if (["%%", "<!--"].includes(frontMarkup)) {
selectedText = " " + selectedText + " ";
// account for shift in positining for the cursor repositioning
eo = eo + 2;
blen++;
alen++;
}
editor.replaceSelection(frontMarkup + selectedText + endMarkup);
contentChangeList.push(
{ line: preAnchor.line, shift: blen },
{ line: preHead.line, shift: alen }
);
preAnchor.ch += blen;
preHead.ch += blen;
}
// Undo Markup (outside selection, inside not necessary as trimmed already)
if (markupOutsideSel()) {
editor.setSelection(offToPos(so - blen), offToPos(eo + alen));
editor.replaceSelection(selectedText);
contentChangeList.push(
{ line: preAnchor.line, shift: -blen },
{ line: preHead.line, shift: -alen }
);
preAnchor.ch -= blen;
preHead.ch -= blen;
}
if (lineMode === "single") editor.setSelection(preAnchor, preHead);
}
function wrapMultiLine() {
const selAnchor = editor.getCursor("from");
selAnchor.ch = 0;
const selHead = editor.getCursor("to");
selHead.ch = editor.getLine(selHead.line).length;
if (frontMarkup === "`") { // switch to fenced code instead of inline code
frontMarkup = "```";
endMarkup = "```";
alen = 3;
blen = 3;
}
else if (frontMarkup === "$") { // switch to block mathjax syntax instead of inline mathjax
frontMarkup = "$$";
endMarkup = "$$";
alen = 2;
blen = 2;
}
// do Markup
if (!markupOutsideMultiline(selAnchor, selHead)) {
editor.setSelection(selAnchor);
editor.replaceSelection(frontMarkup + "\n");
selHead.line++; // extra line to account for shift from inserting frontMarkup
editor.setSelection(selHead);
editor.replaceSelection("\n" + endMarkup);
// when fenced code, position cursor for language definition
if (frontMarkup === "```") {
const languageDefPos = selAnchor;
languageDefPos.ch = 3;
editor.setSelection(languageDefPos);
}
}
// undo Block Markup
if (markupOutsideMultiline(selAnchor, selHead)) {
deleteLine(selAnchor.line - 1);
deleteLine(selHead.line); // not "+1" due to shift from previous line deletion
}
}
async function insertURLtoMDLink () {
const URLregex = constant.URL_REGEX;
const cbText = (await navigator.clipboard.readText()).trim();
let frontMarkup_ = frontMarkup;
let endMarkup_ = endMarkup;
if (URLregex.test(cbText)) {
endMarkup_ = "](" + cbText + ")";
const urlExtension = cbText.split(".").pop();
if (constant.IMAGEEXTENSIONS.includes(urlExtension)) frontMarkup_ = "![";
}
return [frontMarkup_, endMarkup_];
}
function smartDelete() {
// expand selection to prevent double spaces after deletion
if (isOutsideSel(" ", "")) {
const anchor = editor.getCursor("from");
const head = editor.getCursor("to");
if (anchor.ch) anchor.ch--; // do not apply to first line position
editor.setSelection (anchor, head);
}
// delete
editor.replaceSelection ("");
}
function smartCaseSwitch(preAnchor: EditorPosition, preHead: EditorPosition) {
function sentenceCase (str: string) {
// Move i to index of first letter (using this trick: https://stackoverflow.com/a/32567789)
let i = 0;
while (str.charAt(i).toLowerCase() === str.charAt(i).toUpperCase()) {
i++;
if (i > str.length) break;
}
return str.charAt(i).toUpperCase() + str.slice(i+1).toLowerCase();
}
let sel = editor.getSelection();
// Other/Lower → Sentence, Sentence → Upper, Upper → Lower
if (sel === sel.toLowerCase()) sel = sentenceCase(sel);
else if (sel === sentenceCase(sel)) sel = sel.toUpperCase();
else if (sel === sel.toUpperCase()) sel = sel.toLowerCase();
else sel = sentenceCase(sel);
editor.replaceSelection (sel);
editor.setSelection(preAnchor, preHead);
}
function smartHeading (direction: string) {
const { line: lineNumber, ch: column } = editor.getCursor("head");
const lineContent = editor.getLine(lineNumber);
const hasHeading = lineContent.match(/^#{1,6}(?= )/);
let currentHeadingLvl;
let newLineContent;
let newColumn;
if (direction === "increase" && hasHeading) {
currentHeadingLvl = hasHeading[0];
if (currentHeadingLvl.length < 6) {
newLineContent = "#" + lineContent;
newColumn = column + 1;
} else {
newLineContent = lineContent.slice(7);
if (column > 6) newColumn = column - 7;
else newColumn = 0;
}
} else if (direction === "increase" && !hasHeading) {
newLineContent = "# " + lineContent;
newColumn = column + 2;
} else if (direction === "decrease" && hasHeading) {
currentHeadingLvl = hasHeading[0];
if (currentHeadingLvl.length > 1) {
newLineContent = lineContent.slice(1);
newColumn = column - 1;
} else {
newLineContent = lineContent.slice(2);
newColumn = column - 2;
}
} else if (direction === "decrease" && !hasHeading) {
newLineContent = "###### " + lineContent;
newColumn = column + 7;
}
editor.setLine(lineNumber, newLineContent);
editor.setCursor(lineNumber, newColumn);
}
// MAIN
//-------------------------------------------------------------------
log("\nSmarterMD Hotkeys triggered\n---------------------------");
// does not have to occur in multi-cursor loop since it already works
// on every cursor
if (frontMarkup === "new-line") {
// @ts-expect-error, not typed
editor.newlineOnly();
return;
}
// TODO: remove this
// eslint-disable-next-line require-atomic-updates
if (endMarkup === "]()") [frontMarkup, endMarkup] = await insertURLtoMDLink();
let blen = frontMarkup.length;
let alen = endMarkup.length;
// saves the amount of position shift for each line
// used to calculate correct positions for multi-cursor
const contentChangeList: contentChange[] = [];
const allCursors = editor.listSelections();
// sets markup for each cursor/selection
allCursors.forEach(sel => {
// account for shifts in Editor Positions due to applying markup to previous cursors
sel.anchor = recalibratePos (sel.anchor);
sel.head = recalibratePos (sel.head);
editor.setSelection(sel.anchor, sel.head);
// prevent things like triple-click selection from triggering multi-line
trimSelection();
// run special cases instead
if (frontMarkup === "delete") {
log ("Smart Delete");
expandSelection();
smartDelete();
}
else if (frontMarkup === "case-switch") {
log ("Smart Case Switch");
const { anchor: preSelExpAnchor, head: preSelExpHead } = expandSelection();
smartCaseSwitch(preSelExpAnchor, preSelExpHead);
}
else if (frontMarkup === "heading") {
log ("Smart Toggle Heading");
smartHeading(endMarkup);
}
// wrap single line selection
else if (!multiLineSel()) {
log ("single line");
const { anchor: preSelExpAnchor, head: preSelExpHead } = expandSelection();
applyMarkup(preSelExpAnchor, preSelExpHead, "single");
}
// Wrap multi-line selection
else if (multiLineSel() && isMultiLineMarkup()) {
log ("Multiline Wrap");
wrapMultiLine();
}
// Wrap *each* line of multi-line selection
else if (multiLineSel() && !isMultiLineMarkup()) {
let pointerOff = startOffset();
const lines = editor.getSelection().split("\n");
log ("lines: " + lines.length.toString());
// get offsets for each line and apply markup to each
lines.forEach (line => {
console.log("");
editor.setSelection(offToPos(pointerOff), offToPos(pointerOff + line.length));
const { anchor: preSelExpAnchor, head: preSelExpHead } = expandSelection();
// Move Pointer to next line
pointerOff += line.length + 1; // +1 to account for line break
if (markupOutsideSel()) pointerOff-= blen + alen; // account for removed markup
else pointerOff += blen + alen; // account for added markup
applyMarkup(preSelExpAnchor, preSelExpHead, "multi");
});
}
});
}
}