|
2852 | 2852 | closeC = character
|
2853 | 2853 | }
|
2854 | 2854 | }
|
2855 |
| - return [openC, closeC] |
| 2855 | + |
| 2856 | + if (!openC || !closeC) { |
| 2857 | + return null |
| 2858 | + } else { |
| 2859 | + return [openC, closeC] |
| 2860 | + } |
2856 | 2861 | }
|
2857 | 2862 |
|
2858 |
| - function replaceSurround (cm, searchCharacter, replaceCharacter) { |
| 2863 | + function replaceSurround (cm, searchCharacter, replacePair, addSpace = false) { |
2859 | 2864 | var searchPair = transformCharacterPair(searchCharacter)
|
2860 |
| - var replacePair = transformCharacterPair(replaceCharacter) |
| 2865 | + |
| 2866 | + if (!replacePair) { |
| 2867 | + return |
| 2868 | + } |
2861 | 2869 |
|
2862 | 2870 | var openIndex, closeIndex, lineContent = cm.getLine(cursor.line)
|
2863 | 2871 | openIndex = lineContent.slice(0, cursor.ch).lastIndexOf(searchPair[0])
|
|
2869 | 2877 |
|
2870 | 2878 | var inner = lineContent.slice(openIndex + 1, closeIndex + cursor.ch)
|
2871 | 2879 |
|
2872 |
| - var addSpace = openCs.includes(replaceCharacter) |
2873 |
| - |
2874 | 2880 | var openPos = { ch: openIndex, line: cursor.line }
|
2875 | 2881 | var closePos = { ch: cursor.ch + closeIndex + 1, line: cursor.line }
|
2876 | 2882 |
|
|
2896 | 2902 | var tmp = selectCompanionObject(cm, cursor, searchCharacter, true)
|
2897 | 2903 | const replacePair = transformCharacterPair(replaceCharacter)
|
2898 | 2904 |
|
| 2905 | + if (!replacePair) { |
| 2906 | + return |
| 2907 | + } |
| 2908 | + |
2899 | 2909 | replaceCharacterAt(cm, replacePair[0], tmp.start)
|
2900 | 2910 | replaceCharacterAt(cm, replacePair[1], { ch: tmp.end.ch - 1, line: tmp.end.line })
|
2901 | 2911 | }
|
2902 | 2912 |
|
2903 |
| - if (mirroredPairs[actionArgs.search]) { |
2904 |
| - replaceSurround(cm, actionArgs.search, character) |
2905 |
| - } else if (multilinePairs[actionArgs.search]) { |
2906 |
| - replaceMultilineSurround(cm, actionArgs.search, character) |
2907 |
| - } |
| 2913 | + if (character === '<') { |
| 2914 | + // editing tags object |
| 2915 | + showPrompt(cm, { |
| 2916 | + onCloseDialog: function (inputRef) { |
| 2917 | + var input = inputRef.getElementsByTagName("input")[0].value |
| 2918 | + // Give the prompt some time to close so that if processCommand shows |
| 2919 | + // an error, the elements don't overlap. |
| 2920 | + vimGlobalState.exCommandHistoryController.pushInput(input + '>'); |
| 2921 | + vimGlobalState.exCommandHistoryController.reset(); |
| 2922 | + |
| 2923 | + input = '<' + input + '>'; |
| 2924 | + var openTagRegex = /<([A-Za-z][A-Za-z0-9]*)\b[^>]*>/ |
| 2925 | + var match = input.match(openTagRegex) |
| 2926 | + if (!match) { |
| 2927 | + return |
| 2928 | + } |
2908 | 2929 |
|
2909 |
| - cm.setCursor(cursor) |
| 2930 | + replaceSurround(cm, actionArgs.search, [ |
| 2931 | + input, |
| 2932 | + '</' + match[1] + '>' |
| 2933 | + ]) |
| 2934 | + }, |
| 2935 | + prefix: '<', |
| 2936 | + onKeyDown: function (e, input, close) { |
| 2937 | + var keyName = CodeMirror.keyName(e), up, offset; |
| 2938 | + if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[' || |
| 2939 | + (keyName == 'Backspace' && input == '')) { |
| 2940 | + vimGlobalState.exCommandHistoryController.pushInput(input); |
| 2941 | + vimGlobalState.exCommandHistoryController.reset(); |
| 2942 | + CodeMirror.e_stop(e); |
| 2943 | + clearInputState(cm); |
| 2944 | + close(); |
| 2945 | + cm.focus(); |
| 2946 | + } |
| 2947 | + if (e.key === '>') { |
| 2948 | + close(input) |
| 2949 | + CodeMirror.e_stop(e); |
| 2950 | + close() |
| 2951 | + } else if (keyName == 'Up' || keyName == 'Down') { |
| 2952 | + CodeMirror.e_stop(e); |
| 2953 | + up = keyName == 'Up' ? true : false; |
| 2954 | + offset = e.target ? e.target.selectionEnd : 0; |
| 2955 | + input = vimGlobalState.exCommandHistoryController.nextMatch(input, up) || ''; |
| 2956 | + close(input); |
| 2957 | + if (offset && e.target) e.target.selectionEnd = e.target.selectionStart = Math.min(offset, e.target.value.length); |
| 2958 | + } else if (keyName == 'Ctrl-U') { |
| 2959 | + // Ctrl-U clears input. |
| 2960 | + CodeMirror.e_stop(e); |
| 2961 | + close(''); |
| 2962 | + } else { |
| 2963 | + if ( keyName != 'Left' && keyName != 'Right' && keyName != 'Ctrl' && keyName != 'Alt' && keyName != 'Shift') |
| 2964 | + vimGlobalState.exCommandHistoryController.reset(); |
| 2965 | + } |
| 2966 | + } |
| 2967 | + }); |
| 2968 | + } else { |
| 2969 | + if (mirroredPairs[actionArgs.search]) { |
| 2970 | + var replacePair = transformCharacterPair(character) |
| 2971 | + var addSpace = openCs.includes(character) |
| 2972 | + replaceSurround(cm, actionArgs.search, replacePair, addSpace) |
| 2973 | + } else if (multilinePairs[actionArgs.search]) { |
| 2974 | + replaceMultilineSurround(cm, actionArgs.search, character) |
| 2975 | + } |
| 2976 | + |
| 2977 | + cm.setCursor(cursor) |
| 2978 | + } |
2910 | 2979 | }
|
2911 | 2980 | };
|
2912 | 2981 |
|
|
4070 | 4139 | if (cm.openDialog) {
|
4071 | 4140 | cm.openDialog(template, onClose, { bottom: true, value: options.value,
|
4072 | 4141 | onKeyDown: options.onKeyDown, onKeyUp: options.onKeyUp,
|
4073 |
| - selectValueOnOpen: false}); |
| 4142 | + selectValueOnOpen: false, onClose: options.onCloseDialog}); |
4074 | 4143 | }
|
4075 | 4144 | else {
|
4076 | 4145 | onClose(prompt(shortText, ''));
|
|
0 commit comments