master
svelte 116 lines 3.42 KB
Raw
1 <script lang="ts">
2 import { createEventDispatcher } from "svelte";
3 import ContextMenu from "../utility/ContextMenu.svelte";
4 import { commands } from "../../config/commands";
5 const dispatch = createEventDispatcher();
6
7 export let id = 0;
8 export let label = "Untitled-1";
9 export let path = "";
10 export let active = false;
11 export let saved = true;
12
13 let tab = null;
14
15 function handleSelect(tabid) {
16 dispatch("select", {tabid: tabid})
17 }
18 function handleClose(tabid) {
19 dispatch("closetab", {tabid: tabid});
20 }
21
22 let contextmenu = false;
23 let contextmenuitems = [
24 {name: "Close Tab", shortcut: commands.closeTab.keybind, action: () => {handleClose(id)}},
25 {name: "Close All Tabs", shortcut: "", action: commands.closeAllTabs.command},
26 {name: "Open In Explorer", disabled: path === label, shortcut: commands.openInExplorer.keybind, action: () => {commands.openInExplorer.command(path)}},
27 {name: "Rename File", disabled: path === label, shortcut: commands.renameFile.keybind, action: () => {commands.renameFile.command(label, path)}},
28 ]
29 </script>
30 <div bind:this={tab} title={path} id={`editorTab-${id}`} class="tab" class:active={active}>
31 <!-- svelte-ignore a11y-click-events-have-key-events -->
32 <div class="tab-content" on:mousedown = {(e) => { if (e.button === 0) handleSelect(id);}} on:mouseup={(e) => {if (e.button === 2) contextmenu = true;}}>
33 <span class="tab-label">{label}</span>
34 <span class="save-state" class:saved></span>
35 </div>
36 <!-- svelte-ignore a11y-click-events-have-key-events -->
37 <div class="close-tab">
38 <span title="Close tab" on:click={() => {handleClose(id)}}></span>
39 </div>
40 </div>
41
42 {#if contextmenu}
43 <ContextMenu target={tab} items={contextmenuitems}></ContextMenu>
44 {/if}
45
46 <style lang="scss">
47 .tab {
48 height: 100%;
49 min-width: min-content;
50 flex-grow: 0.05;
51 display: flex;
52 overflow: hidden;
53 justify-content: space-between;
54 align-items: center;
55 font-size: 14px;
56 cursor: pointer;
57 padding: 0 10px;
58 }
59 .tab-content::-webkit-scrollbar {
60 height: 4px;
61 }
62 .tab-content::-webkit-scrollbar {
63 background-color: #1b5fdd;
64 }
65 .tab-content {
66 display: flex;
67 justify-content: center;
68 align-items: center;
69 overflow-x: overlay;
70 overflow-y: hidden;
71 height: 100%;
72 padding-left: 2px;
73 .save-state {
74 &.saved {
75 display: none !important;
76 }
77 display: block;
78 width: 6px;
79 height: 6px;
80 border-radius: 50%;
81 left: -11px;
82 top: 0.5px;
83 position: relative;
84 }
85 }
86 .tab-label {
87 text-overflow: ellipsis;
88 white-space: nowrap;
89 padding-right: 20px;
90 }
91 .close-tab span {
92 font-size: 11px;
93 display: flex;
94 justify-content: center;
95 width: 100%;
96 height: 100%;
97 align-items: center;
98 &::before {
99 content: "\2715";
100 }
101 }
102 .close-tab span:hover {
103 transition: 0.1s;
104 border-radius: 3px;
105 }
106 .close-tab {
107 width: 18px;
108 height: 18px;
109 margin-left: -0.5rem;
110 margin-right: 0.5rem;
111 display: flex;
112 justify-content: center;
113 position: relative;
114 left: 10px;
115 }
116 </style>