codemirror实现浏览器中打开本地电脑文件夹目录树及多tab选项卡编辑文本文件代码

代码语言:html

所属分类:其他

代码描述:codemirror实现浏览器中打开本地电脑文件夹目录树及多tab选项卡编辑文本文件代码,通过showDirectoryPicker来直接在浏览器中操作本地电脑任意文件夹中的文件和子目录,模仿vscode直接多tab选项卡打开和编辑文本文件及代码,还能保存修改后的代码,切换tab和关闭编辑器,目录树种可单击折叠目录,双击文件右侧打开。

代码标签: codemirror 浏览器 打开 本地 电脑 文件夹 目录 tab 选项卡 编辑 文本

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Code Editor</title>
     
  <link rel='stylesheet' href='//repo.bfw.wiki/bfwrepo/js/codemirror/lib/codemirror.css'>
<link rel='stylesheet' href='//repo.bfw.wiki/bfwrepo/js/codemirror/theme/material.css'>
  
    <style>
    /* 自定义滚动条样式 */
        ::-webkit-scrollbar {
            width: 10px;
            height: 10px;
        }

        ::-webkit-scrollbar-track {
            background: #1e1e1e;
            border-radius: 5px;
        }

        ::-webkit-scrollbar-thumb {
            background: #444;
            border-radius: 5px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: #555;
        }

        /* Firefox 滚动条样式 */
        * {
            scrollbar-color: #444 #1e1e1e;
            scrollbar-width: thin;
        }

        body {
            margin: 0;
            padding: 0;
            display: flex;
            height: 100vh;
            font-family: Arial, sans-serif;
            background-color: #1e1e1e;
            color: white;
            overflow: hidden;
        }
        #sidebar {
            width: 250px;
            background-color: #252526;
            padding: 10px;
            overflow-y: auto;
            border-right: 1px solid #444;
        }
        #editor {
            flex: 1;
            background-color: #1e1e1e;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        .file-item, .folder-item {
            cursor: pointer;
            padding: 5px;
            margin: 5px 0;
            border-radius: 3px;
            display: flex;
            align-items: center;
        }
        .file-item:hover, .folder-item:hover {
            background-color: #2a2d2e;
        }
        .folder-item::before, .file-item::before {
            content: '';
            display: inline-block;
            width: 16px;
            height: 16px;
            margin-right: 5px;
            background-size: cover;
        }
        .folder-item::before {
            background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0id2hpdGUiPjxwYXRoIGQ9Ik0xMCA0SDRjLTEuMSAwLTEuOTkuOS0xLjk5IDJMMiAxOGMwIDEuMS45IDIgMiAyaDE2YzEuMSAwIDItLjkgMi0yVjhjMC0xLjEtLjktMi0yLTJoLThsLTItMnoiLz48L3N2Zz4=');
        }
        .file-item::before {
            background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0id2hpdGUiPjxwYXRoIGQ9Ik0xNCAySDZjLTEuMSAwLTEuOTkuOS0xLjk5IDJMMyAyMGMwIDEuMS45IDIgMiAyaDEyYzEuMSAwIDItLjkgMi0yVjhsLTYtNnptNCAxOEg2VjRoN3Y1aDV2MTF6Ii8+PC9zdmc+');
        }
        .folder-item.collapsed::before {
            background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0id2hpdGUiPjxwYXRoIGQ9Ik0xMCA4SDRjLTEuMSAwLTEuOTkuOS0xLjk5IDJMMiAxOGMwIDEuMS45IDIgMiAyaDE2YzEuMSAwIDItLjkgMi0yVjhjMC0xLjEtLjktMi0yLTJoLThsLTItMnoiLz48L3N2Zz4=');
        }
        .folder-item.expanded::before {
            background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0id2hpdGUiPjxwYXRoIGQ9Ik0xOSAxMEg1Yy0xLjEgMC0yIC45LTIgMnY4YzAgMS4xLjkgMiAyIDJoMTRjMS4xIDAgMi0uOSAyLTJ2LThjMC0xLjEtLjktMi0yLTJ6bS04IDZIOXYtMmgydjJ6bTAtNEg5di0yaDJ2MnptNC40IDRoLTMuOGMtLjMgMC0uNi0uMi0uOC0uNGwtMS4yLTEuNmgxLjJsLjYuOWg4LjJsLjYtLjkxIDEuMiAxLjYxYy0uMi4yLS41LjQtLjguNHoiLz48L3N2Zz4=');
        }
        #tabs {
            display: flex;
            background-color: #252526;
            padding: 5px;
            border-bottom: 1px solid #444;
        }
        .tab {
            display: flex;
            align-items: center;
            padding: 8px 12px;
            margin-right: 5px;
            cursor: pointer;
            background-color: #2a2d2e;
            border-radius: 3px;
            position: relative;
        }
        .tab.active {
            background-color: #0e639c;
        }
        .close-button {
            margin-left: 8px;
            cursor: pointer;
            font-size: 14px;
            color: #ccc;
        }
        .close-button:hover {
            color: white;
        }
        #save-button {
            position: absolute;
            top: 10px;
            right: 10px;
            background-color: #0e639c;
            color: white;
            border: none;
            padding: 8px 12px;
            border-radius: 3px;
            cursor: pointer;
        }
        #save-button:hover {
            background-color: #1177bb;
        }
        .CodeMirror {
            height: 100%; /* 确保编辑器占据整个容器高度 */
        }
        .sub-container {
            margin-left: 20px;
            display: none;
        }
        .folder-item.expanded + .sub-container {
            display: block;
        }
        #code-editor-container {
            flex: 1;
            display: none; /* 默认隐藏 */
            height: 100vh;
            overflow: hidden;
        }
        #c.........完整代码请登录后点击上方下载按钮下载查看

网友评论0