Files
FOF-ACE-Editor/lib/ace/src-noconflict/ext-searchbox.js
2025-08-16 16:14:03 +08:00

748 lines
36 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

ace.define("ace/ext/searchbox.css", ["require", "exports", "module"], function (require, exports, module) {
module.exports = "\n\n/* ------------------------------------------------------------------------------------------\n * Editor Search Form\n * --------------------------------------------------------------------------------------- */\n.ace_search {\n background-color: #ddd;\n color: #666;\n border: 1px solid #cbcbcb;\n border-top: 0 none;\n overflow: hidden;\n margin: 0;\n padding: 4px 6px 0 4px;\n position: absolute;\n top: 0;\n z-index: 99;\n white-space: normal;\n}\n.ace_search.left {\n border-left: 0 none;\n border-radius: 0px 0px 5px 0px;\n left: 0;\n}\n.ace_search.right {\n border-radius: 0px 0px 0px 5px;\n border-right: 0 none;\n right: 0;\n}\n\n.ace_search_form, .ace_replace_form {\n margin: 0 20px 4px 0;\n overflow: hidden;\n line-height: 1.9;\n}\n.ace_replace_form {\n margin-right: 0;\n}\n.ace_search_form.ace_nomatch {\n outline: 1px solid red;\n}\n\n.ace_search_field {\n border-radius: 3px 0 0 3px;\n background-color: white;\n color: black;\n border: 1px solid #cbcbcb;\n border-right: 0 none;\n outline: 0;\n padding: 0;\n font-size: inherit;\n margin: 0;\n line-height: inherit;\n padding: 0 6px;\n min-width: 17em;\n vertical-align: top;\n min-height: 1.8em;\n box-sizing: content-box;\n}\n.ace_searchbtn {\n border: 1px solid #cbcbcb;\n line-height: inherit;\n display: inline-block;\n padding: 0 6px;\n background: #fff;\n border-right: 0 none;\n border-left: 1px solid #dcdcdc;\n cursor: pointer;\n margin: 0;\n position: relative;\n color: #666;\n}\n.ace_searchbtn:last-child {\n border-radius: 0 3px 3px 0;\n border-right: 1px solid #cbcbcb;\n}\n.ace_searchbtn:disabled {\n background: none;\n cursor: default;\n}\n.ace_searchbtn:hover {\n background-color: #eef1f6;\n}\n.ace_searchbtn.prev, .ace_searchbtn.next {\n padding: 0px 0.7em\n}\n.ace_searchbtn.prev:after, .ace_searchbtn.next:after {\n content: \"\";\n border: solid 2px #888;\n width: 0.5em;\n height: 0.5em;\n border-width: 2px 0 0 2px;\n display:inline-block;\n transform: rotate(-45deg);\n}\n.ace_searchbtn.next:after {\n border-width: 0 2px 2px 0 ;\n}\n.ace_searchbtn_close {\n background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAcCAYAAABRVo5BAAAAZ0lEQVR42u2SUQrAMAhDvazn8OjZBilCkYVVxiis8H4CT0VrAJb4WHT3C5xU2a2IQZXJjiQIRMdkEoJ5Q2yMqpfDIo+XY4k6h+YXOyKqTIj5REaxloNAd0xiKmAtsTHqW8sR2W5f7gCu5nWFUpVjZwAAAABJRU5ErkJggg==) no-repeat 50% 0;\n border-radius: 50%;\n border: 0 none;\n color: #656565;\n cursor: pointer;\n font: 16px/16px Arial;\n padding: 0;\n height: 14px;\n width: 14px;\n top: 9px;\n right: 7px;\n position: absolute;\n}\n.ace_searchbtn_close:hover {\n background-color: #656565;\n background-position: 50% 100%;\n color: white;\n}\n\n.ace_button {\n margin-left: 2px;\n cursor: pointer;\n -webkit-user-select: none;\n -moz-user-select: none;\n -o-user-select: none;\n -ms-user-select: none;\n user-select: none;\n overflow: hidden;\n opacity: 0.7;\n border: 1px solid rgba(100,100,100,0.23);\n padding: 1px;\n box-sizing: border-box!important;\n color: black;\n}\n\n.ace_button:hover {\n background-color: #eee;\n opacity:1;\n}\n.ace_button:active {\n background-color: #ddd;\n}\n\n.ace_button.checked {\n border-color: #3399ff;\n opacity:1;\n}\n\n.ace_search_options{\n margin-bottom: 3px;\n text-align: right;\n -webkit-user-select: none;\n -moz-user-select: none;\n -o-user-select: none;\n -ms-user-select: none;\n user-select: none;\n clear: both;\n}\n\n.ace_search_counter {\n float: left;\n font-family: arial;\n padding: 0 8px;\n}";
});
ace.define("ace/ext/searchbox", ["require", "exports", "module", "ace/lib/dom", "ace/lib/lang", "ace/lib/event", "ace/ext/searchbox.css", "ace/keyboard/hash_handler", "ace/lib/keys"], function (require, exports, module) {
"use strict";
var dom = require("../lib/dom");
var lang = require("../lib/lang");
var event = require("../lib/event");
var searchboxCss = require("./searchbox.css");
var HashHandler = require("../keyboard/hash_handler").HashHandler;
var keyUtil = require("../lib/keys");
var MAX_COUNT = 999;
var Search = require("../search").Search;
var search = new Search();
dom.importCssString(searchboxCss, "ace_searchbox", false);
var SearchBox = function (editor, range, showReplaceForm) {
var div = dom.createElement("div");
dom.buildDom(["div", {
class: "ace_search right"
},
["span", {
action: "hide",
class: "ace_searchbtn_close"
}],
["div", {
class: "ace_search_form"
},
["input", {
class: "ace_search_field",
placeholder: "搜索",
spellcheck: "false"
}],
["span", {
action: "findPrev",
class: "ace_searchbtn prev"
}, "\u200b"],
["span", {
action: "findNext",
class: "ace_searchbtn next"
}, "\u200b"],
["span", {
action: "findAll",
class: "ace_searchbtn",
title: "Alt-Enter"
}, "所有"]
],
["div", {
class: "ace_replace_form"
},
["input", {
class: "ace_search_field",
placeholder: "替换为",
spellcheck: "false"
}],
["span", {
action: "replaceAndFindNext",
class: "ace_searchbtn"
}, "替换"],
["span", {
action: "replaceAll",
class: "ace_searchbtn"
}, "替换所有"]
],
["div", {
class: "ace_search_options"
},
["span", {
action: "toggleReplace",
class: "ace_button",
title: "替换模式",
style: "float:left;margin-top:-2px;padding:0 5px;"
}, "+"],
["span", {
class: "ace_search_counter"
}],
["span", {
action: "toggleRegexpMode",
class: "ace_button",
title: "正则搜索"
}, ".*"],
["span", {
action: "toggleCaseSensitive",
class: "ace_button",
title: "区分大小写搜索"
}, "Aa"],
["span", {
action: "toggleWholeWords",
class: "ace_button",
title: "单词搜索"
}, "\\b"],
["span", {
action: "searchInSelection",
class: "ace_button",
title: "选择搜索"
}, "S"]
]
], div);
this.element = div.firstChild;
this.setSession = this.setSession.bind(this);
this.$init();
this.setEditor(editor);
dom.importCssString(searchboxCss, "ace_searchbox", editor.container);
};
(function () {
this.setEditor = function (editor) {
editor.searchBox = this;
editor.renderer.scroller.appendChild(this.element);
this.editor = editor;
};
this.setSession = function (e) {
this.searchRange = null;
this.$syncOptions(true);
};
this.$initElements = function (sb) {
this.searchBox = sb.querySelector(".ace_search_form");
this.replaceBox = sb.querySelector(".ace_replace_form");
this.searchOption = sb.querySelector("[action=searchInSelection]");
this.replaceOption = sb.querySelector("[action=toggleReplace]");
this.regExpOption = sb.querySelector("[action=toggleRegexpMode]");
this.caseSensitiveOption = sb.querySelector("[action=toggleCaseSensitive]");
this.wholeWordOption = sb.querySelector("[action=toggleWholeWords]");
this.searchInput = this.searchBox.querySelector(".ace_search_field");
this.replaceInput = this.replaceBox.querySelector(".ace_search_field");
this.searchCounter = sb.querySelector(".ace_search_counter");
};
this.$init = function () {
var sb = this.element;
this.$initElements(sb);
var _this = this;
event.addListener(sb, "mousedown", function (e) {
setTimeout(function () {
_this.activeInput.focus();
}, 0);
event.stopPropagation(e);
});
event.addListener(sb, "click", function (e) {
var t = e.target || e.srcElement;
var action = t.getAttribute("action");
if (action && _this[action])
_this[action]();
else if (_this.$searchBarKb.commands[action])
_this.$searchBarKb.commands[action].exec(_this);
event.stopPropagation(e);
});
event.addCommandKeyListener(sb, function (e, hashId, keyCode) {
var keyString = keyUtil.keyCodeToString(keyCode);
var command = _this.$searchBarKb.findKeyCommand(hashId, keyString);
if (command && command.exec) {
command.exec(_this);
event.stopEvent(e);
}
});
this.$onChange = lang.delayedCall(function () {
_this.find(false, false);
});
event.addListener(this.searchInput, "input", function () {
_this.$onChange.schedule(20);
});
event.addListener(this.searchInput, "focus", function () {
_this.activeInput = _this.searchInput;
_this.searchInput.value && _this.highlight();
});
event.addListener(this.replaceInput, "focus", function () {
_this.activeInput = _this.replaceInput;
_this.searchInput.value && _this.highlight();
});
};
this.$closeSearchBarKb = new HashHandler([{
bindKey: "Esc",
name: "closeSearchBar",
exec: function (editor) {
editor.searchBox.hide();
}
}]);
this.$searchBarKb = new HashHandler();
this.$searchBarKb.bindKeys({
"Ctrl-f|Command-f": function (sb) {
var isReplace = sb.isReplace = !sb.isReplace;
sb.replaceBox.style.display = isReplace ? "" : "none";
sb.replaceOption.checked = false;
sb.$syncOptions();
sb.searchInput.focus();
},
"Ctrl-H|Command-Option-F": function (sb) {
if (sb.editor.getReadOnly())
return;
sb.replaceOption.checked = true;
sb.$syncOptions();
sb.replaceInput.focus();
},
"Ctrl-G|Command-G": function (sb) {
sb.findNext();
},
"Ctrl-Shift-G|Command-Shift-G": function (sb) {
sb.findPrev();
},
"esc": function (sb) {
setTimeout(function () {
sb.hide();
});
},
"Return": function (sb) {
if (sb.activeInput == sb.replaceInput)
sb.replace();
sb.findNext();
},
"Shift-Return": function (sb) {
if (sb.activeInput == sb.replaceInput)
sb.replace();
sb.findPrev();
},
"Alt-Return": function (sb) {
if (sb.activeInput == sb.replaceInput)
sb.replaceAll();
sb.findAll();
},
"Tab": function (sb) {
(sb.activeInput == sb.replaceInput ? sb.searchInput : sb.replaceInput).focus();
}
});
this.$searchBarKb.addCommands([{
name: "toggleRegexpMode",
bindKey: {
win: "Alt-R|Alt-/",
mac: "Ctrl-Alt-R|Ctrl-Alt-/"
},
exec: function (sb) {
sb.regExpOption.checked = !sb.regExpOption.checked;
sb.$syncOptions();
}
}, {
name: "toggleCaseSensitive",
bindKey: {
win: "Alt-C|Alt-I",
mac: "Ctrl-Alt-R|Ctrl-Alt-I"
},
exec: function (sb) {
sb.caseSensitiveOption.checked = !sb.caseSensitiveOption.checked;
sb.$syncOptions();
}
}, {
name: "toggleWholeWords",
bindKey: {
win: "Alt-B|Alt-W",
mac: "Ctrl-Alt-B|Ctrl-Alt-W"
},
exec: function (sb) {
sb.wholeWordOption.checked = !sb.wholeWordOption.checked;
sb.$syncOptions();
}
}, {
name: "toggleReplace",
exec: function (sb) {
sb.replaceOption.checked = !sb.replaceOption.checked;
sb.$syncOptions();
}
}, {
name: "searchInSelection",
exec: function (sb) {
sb.searchOption.checked = !sb.searchRange;
sb.setSearchRange(sb.searchOption.checked && sb.editor.getSelectionRange());
sb.$syncOptions();
}
}]);
this.setSearchRange = function (range) {
this.searchRange = range;
if (range) {
this.searchRangeMarker = this.editor.session.addMarker(range, "ace_active-line");
} else if (this.searchRangeMarker) {
this.editor.session.removeMarker(this.searchRangeMarker);
this.searchRangeMarker = null;
}
};
this.$syncOptions = function (preventScroll) {
dom.setCssClass(this.replaceOption, "checked", this.searchRange);
dom.setCssClass(this.searchOption, "checked", this.searchOption.checked);
this.replaceOption.textContent = this.replaceOption.checked ? "-" : "+";
dom.setCssClass(this.regExpOption, "checked", this.regExpOption.checked);
dom.setCssClass(this.wholeWordOption, "checked", this.wholeWordOption.checked);
dom.setCssClass(this.caseSensitiveOption, "checked", this.caseSensitiveOption.checked);
var readOnly = this.editor.getReadOnly();
this.replaceOption.style.display = readOnly ? "none" : "";
this.replaceBox.style.display = this.replaceOption.checked && !readOnly ? "" : "none";
this.find(false, false, preventScroll);
};
this.highlight = function (re) {
this.editor.session.highlight(re || this.editor.$search.$options.re);
this.editor.renderer.updateBackMarkers();
};
this.find = function (skipCurrent, backwards, preventScroll) {
var range = this.editor.find(this.searchInput.value, {
skipCurrent: skipCurrent,
backwards: backwards,
wrap: true,
regExp: this.regExpOption.checked,
caseSensitive: this.caseSensitiveOption.checked,
wholeWord: this.wholeWordOption.checked,
preventScroll: preventScroll,
range: this.searchRange
});
var noMatch = !range && this.searchInput.value;
dom.setCssClass(this.searchBox, "ace_nomatch", noMatch);
this.editor._emit("findSearchBox", {
match: !noMatch
});
this.highlight();
this.updateCounter();
};
this.updateCounter = function () {
var editor = this.editor;
var regex = editor.$search.$options.re;
var all = 0;
var before = 0;
if (regex) {
var value = this.searchRange ?
editor.session.getTextRange(this.searchRange) :
editor.getValue();
var offset = editor.session.doc.positionToIndex(editor.selection.anchor);
if (this.searchRange)
offset -= editor.session.doc.positionToIndex(this.searchRange.start);
var last = regex.lastIndex = 0;
var m;
while ((m = regex.exec(value))) {
all++;
last = m.index;
if (last <= offset)
before++;
if (all > MAX_COUNT)
break;
if (!m[0]) {
regex.lastIndex = last += 1;
if (last >= value.length)
break;
}
}
}
this.searchCounter.textContent = before + " / " + (all > MAX_COUNT ? MAX_COUNT + "+" : all);
};
this.findNext = function () {
this.find(true, false);
};
this.findPrev = function () {
this.find(true, true);
};
this.findAll = function () {
var range = this.editor.findAll(this.searchInput.value, {
regExp: this.regExpOption.checked,
caseSensitive: this.caseSensitiveOption.checked,
wholeWord: this.wholeWordOption.checked
});
var noMatch = !range && this.searchInput.value;
dom.setCssClass(this.searchBox, "ace_nomatch", noMatch);
this.editor._emit("findSearchBox", {
match: !noMatch
});
this.highlight();
this.hide();
};
this.replace = function () {
if (!this.editor.getReadOnly())
this.editor.replace(this.replaceInput.value);
};
this.replaceAndFindNext = function () {
if (!this.editor.getReadOnly()) {
this.editor.replace(this.replaceInput.value);
this.findNext();
}
};
this.replaceAll = function () {
if (!this.editor.getReadOnly())
this.editor.replaceAll(this.replaceInput.value);
};
this.hide = function () {
this.active = false;
this.setSearchRange(null);
this.editor.off("changeSession", this.setSession);
this.element.style.display = "none";
this.editor.keyBinding.removeKeyboardHandler(this.$closeSearchBarKb);
this.editor.focus();
};
this.show = function (value, isReplace) {
this.active = true;
this.editor.on("changeSession", this.setSession);
this.element.style.display = "";
this.replaceOption.checked = isReplace;
if (value)
this.searchInput.value = value;
this.searchInput.focus();
this.searchInput.select();
this.editor.keyBinding.addKeyboardHandler(this.$closeSearchBarKb);
this.$syncOptions(true);
};
this.isFocused = function () {
var el = document.activeElement;
return el == this.searchInput || el == this.replaceInput;
};
}).call(SearchBox.prototype);
exports.SearchBox = SearchBox;
exports.Search = function (editor, isReplace) {
var sb = editor.searchBox || new SearchBox(editor);
sb.show(editor.session.getTextRange(), isReplace);
};
// 项目搜索
exports.AllFileSearch = function () {
try {
// 获取所有页面代码数据(每次都要重新运行,项目文件可能会更改)
function getAllFileFunction(fileJson = []) {
(fileJson.length > 0) && fileJson.forEach(v => {
let titleArr = v.title.split(".");
let type = titleArr[titleArr.length - 1];
if (['lhtml', 'lcss', 'ljs'].includes(type)) {
if (TAB['tab-' + v.id] && TAB['tab-' + v.id]["file"]) {
ALL_FILE_CODE[v.id] = TAB['tab-' + v.id]["file"]
} else {
ALL_FILE_CODE[v.id] = {
"id": v.id,
"title": v.title,
"href": v.href,
"mode": v.type,
"content": FILE.getFile(v.href),
"line": v.line || {
row: 0,
column: 0
}
}
}
};
if (v.children) {
getAllFileFunction(v.children);
}
})
}
getAllFileFunction(DirectoryTreeJson);
// 添加到编辑器页面,搜索之后再清除
for (const id in ALL_FILE_CODE) {
if (TAB['tab-' + id]) {
ALL_FILE_EDITOR[id] = TAB['tab-' + id];
} else {
ALL_FILE_EDITOR[id] = new EditSession(ALL_FILE_CODE[id]["content"], "ace/mode/" + ALL_FILE_CODE[id]["mode"]);
}
}
// 搜索所有文件
let keyInput = document.querySelector("#fileCodeSearchKey");
keyInput.value = '';
let replaceText = document.querySelector("#replaceText");
replaceText.value = '';
let loadList = $(".search_anim");
let caseSensitive = $("#caseSensitive");
let regExp = $("#regExp");
let wholeWord = $("#wholeWord");
let searchTime;
window.searchData = [];
let option = {
backwards: false,
caseSensitive: $("#caseSensitive").has("layui-btn-primary") ? undefined : true, // 大小写
needle: '',
preventScroll: undefined,
range: undefined,
regExp: $("#regExp").has("layui-btn-primary") ? undefined : true, // 正则
skipCurrent: false,
wholeWord: $("#wholeWord").has("layui-btn-primary") ? undefined : true, // 全字(单词)搜索
wrap: true
};
$("#searchList").html('');
// 显示搜索窗口
layer.open({
type: 1,
title: "全局搜索",
id: "allFileSearch",
area: ["600px", "500px"],
maxmin: true,
content: $(".all_file_search"),
success: function (layero) {
layero.find('.layui-layer-max').hide();
},
min: function (layero, index) {
//当层最小化时触发
layero.find('.layui-layer-max').show();
},
restore: function (layero, index) {
//当层最大化时触发
layero.find('.layui-layer-max').hide();
}
})
if (is_openFileSearch) {
return false;
}
// 切换大小写
caseSensitive.on("click", function () {
caseSensitive.toggleClass("layui-btn-primary");
if (option.caseSensitive) {
option.caseSensitive = undefined;
} else {
option.caseSensitive = true;
}
searchFile()
});
// 切换正则
regExp.on("click", function () {
regExp.toggleClass("layui-btn-primary");
if (option.regExp) {
option.regExp = undefined;
} else {
option.regExp = true;
}
searchFile()
});
// 切换全字(单词)搜索
wholeWord.on("click", function () {
wholeWord.toggleClass("layui-btn-primary");
if (option.wholeWord) {
option.wholeWord = undefined;
} else {
option.wholeWord = true;
}
searchFile()
});
function searchFile() {
if (searchTime) {
clearTimeout(searchTime);
}
$("#searchList").html('');
window.searchData = [];
option.needle = keyInput.value;
if (!option.needle) {
return false;
}
search.set(option);
searchTime = setTimeout(function () {
loadList.show();
let searchListHtml = '';
let findNum = 0;
for (const id in ALL_FILE_EDITOR) {
let [Ranges, Lines] = search.findAll(ALL_FILE_EDITOR[id], true);
if (Ranges && Ranges.length > 0) {
window.searchData.push({
file: ALL_FILE_CODE[id],
lines: Lines,
ranges: Ranges
});
searchListHtml += `<dl><dt>
<h5><i class="iconfont icon-${ALL_FILE_CODE[id]["mode"]}"></i> ${ALL_FILE_CODE[id]["title"]} (${ALL_FILE_CODE[id]["href"]})</h5>
<div class="layui-btn-group">
<button type="button" class="layui-btn layui-btn-xs num">
<i class="layui-icon" title="匹配到${Lines.length}处代码">${Lines.length}</i>
</button>
<button type="button" class="layui-btn layui-btn-xs replaceAllKey" fileId="${id}" title="全部替换">
<i class="layui-icon">&#xe691;</i>
</button>
<button type="button" class="layui-btn layui-btn-xs delAllReplace" fileId="${id}" title="消除">
<i class="layui-icon">&#x1006;</i>
</button>
</div>
</dt>`;
Lines.forEach((v, i) => {
let code = [];
let startChange = 0;
v[0].split("").forEach((v, i2) => {
if (v === "<") {
v = "&lt;"
};
if (i2 === Ranges[i]["start"]["column"]) {
startChange = i2;
if (i2 === Ranges[i]["end"]["column"]) {
code.push(`<font style="color:red">${v}</font>`);
} else {
code.push(`<font style="color:red">`);
code.push(v);
}
} else if (i2 === Ranges[i]["end"]["column"] - 1) {
code.push(v);
code.push(`</font>`);
} else {
code.push(v);
}
});
if (Ranges[i]["start"]["row"] !== Ranges[i]["end"]["row"]) {
code.push(`</font>`);
};
code = code.join("");
if (startChange > 30) {
code = code.substring(Ranges[i]["start"]["column"] - 30);
}
ALL_FILE_CODE[id]["active"] = true;
ALL_FILE_CODE[id]["line"] = JSON.parse(JSON.stringify(Ranges[i]["start"]));
ALL_FILE_CODE[id]["line"]["row"] = ALL_FILE_CODE[id]["line"]["row"] + 1;
ALL_FILE_CODE[id]["content"] = lang.escapeHTML(ALL_FILE_CODE[id]["content"]);
let openFile = JSON.parse(JSON.stringify(ALL_FILE_CODE[id]));
delete openFile["content"]
searchListHtml += `<dd ondblclick='topTabs(${JSON.stringify({"if":"yes","data":[openFile]})});'>
<p>${code.replaceAll("/t","")} </p>
<div class="layui-btn-group">
<button type="button" class="layui-btn layui-btn-xs replaceKey" fileId="${id}" replaceIndex="${i}" title="替换">
<i class="layui-icon">&#xe691;</i>
</button>
<button type="button" class="layui-btn layui-btn-xs delReplace" fileId="${id}" replaceIndex="${i}" title="消除">
<i class="layui-icon">&#x1006;</i>
</button>
</div>
<dd>`;
})
searchListHtml += `</dl>`
// 搜索结果限制
findNum += Ranges.length;
if (findNum > 10000) {
layer.alert("搜索结果超出最大值10000已暂停搜索")
break;
};
};
};
loadList.hide();
if (window.searchData.length > 0) {
// 渲染列表
$("#searchList").html(searchListHtml);
} else {
// 没有搜索结果
$("#searchList").html("<p>没有搜索到匹配内容。</p>")
};
searchTime = null;
}.bind(this), 100);
}
// 替换方法
function replaceFile(data = []) {
// console.log(window.searchData);
let text = replaceText.value;
data.forEach(v => {
if (TAB['tab-' + v.file.id]) {
ALL_FILE_EDITOR[v.file.id] = TAB['tab-' + v.file.id];
for (var i = v.ranges.length - 1; i >= 0; --i) {
TAB['tab-' + v.file.id].replace(v.ranges[i], text);
}
v["file"]["content"] = TAB['tab-' + v.file.id].getValue();
// 给文件更换已更改的状态
$(".layui-tab1 li[lay-id=" + v.file.id + "] .layui-tab-close").addClass('layui-icon-help');
CHANGE[v.file.id] = true;
} else {
for (var i = v.ranges.length - 1; i >= 0; --i) {
ALL_FILE_EDITOR[v.file.id].replace(v.ranges[i], text);
}
v["file"]["content"] = ALL_FILE_EDITOR[v.file.id].getValue();
// 没有打开的文件直接更改保存
}
if(v.file.id!=undefined && v.file.id!="" && v.file.id!=null){
DeletaComPilerCache(v.file.id);//删除文件缓存
}
})
}
// 自动增加输入框的高度
keyInput.addEventListener('input', function (e) {
keyInput.style.height = e.target.scrollHeight + 'px';
});
replaceText.addEventListener('input', function (e) {
replaceText.style.height = e.target.scrollHeight + 'px';
});
// 搜索按钮点击
document.querySelector("#searchBtn").addEventListener("click", function () {
searchFile()
});
// 替换按钮点击
document.querySelector("#replaceBtn").addEventListener("click", function () {
if (window.searchData.length > 0) {
layer.confirm('是否确认全部替换?', {
icon: 3,
title: '询问'
}, function (index) {
replaceFile(window.searchData);
$("#searchList").html('');
window.searchData = [];
layer.close(index);
});
} else {
layer.msg("暂无可替换内容!")
}
});
// 整页替换
$(".search_list").on("click", ".replaceAllKey", function (e) {
let id = $(this).attr("fileId");
let index = window.searchData.findIndex(v => v.file.id == id);
replaceFile([window.searchData[index]]);
window.searchData.splice(index, 1);
$(this).parents("dl").remove();
});
// 整页取消
$(".search_list").on("click", ".delAllReplace", function (e) {
let id = $(this).attr("fileId");
let index = window.searchData.findIndex(v => v.file.id == id);
window.searchData.splice(index, 1);
$(this).parents("dl").remove();
});
// 替换
$(".search_list").on("click", ".replaceKey", function (e) {
let id = $(this).attr("fileId");
let index = $(this).attr("replaceIndex");
let data = window.searchData.find(v => v.file.id == id);
if (!data) {
return false;
}
let data2 = [{
file: data["file"],
ranges: [data["ranges"][index]],
lines: [data["lines"][index]]
}]
replaceFile(data2);
data["file"][index] = data["lines"][index] = null;
let numDom = $(this).parents("dl").find(".num i");
let num = numDom.text() - 1;
numDom.text(num).attr("title", `匹配到${num}处代码`);
if (num === 0) {
$(this).parents("dl").find(".delAllReplace").click();
} else {
$(this).parents("dd").remove();
}
});
// 取消
$(".search_list").on("click", ".delReplace", function (e) {
let id = $(this).attr("fileId");
let index = $(this).attr("replaceIndex");
let data = window.searchData.find(v => v.file.id == id);
if (!data) {
return false;
}
data["ranges"][index] = data["lines"][index] = null;
let numDom = $(this).parents("dl").find(".num i");
let num = numDom.text() - 1;
numDom.text(num).attr("title", `匹配到${num}处代码`);
if (num === 0) {
$(this).parents("dl").find(".delAllReplace").click();
} else {
$(this).parents("dd").remove();
}
});
is_openFileSearch = true;
} catch (error) {
layer.msg("全局搜索错误!联系管理员!")
}
};
});
(function () {
ace.require(["ace/ext/searchbox"], function (m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();