Added line ending to status bar
mellobacon committed
Oct 10, 2022 at 13:56 UTC
915c2db345e4fc50ea383c403ba2bcc43c3072a4
4 files changed
+24
-10
src/components/Content/Editor/CodeMirrorEditor.svelte
+2
-2
@@ -5,7 +5,7 @@
5
import { indentWithTab } from "@codemirror/commands";
6
import { EditorState, Compartment } from "@codemirror/state";
7
import { default_theme } from "./scripts/DefaultTheme";
8
- import { line_column } from "./scripts/Editor";
8
+ import { line_info } from "./scripts/Editor";
9
10
export let hidden = false;
11
let editorElement;
@@ -27,7 +27,7 @@
27
function getLineInfo() {
28
let linenumber = editorView.state.doc.lineAt(editorView.state.selection.main.head).number;
29
let colnumber = editorView.state.selection.ranges[0].head - editorView.state.doc.lineAt(editorView.state.selection.main.head).from
30
- line_column.set({line: linenumber.toString(), col: (colnumber + 1).toString()})
30
+ line_info.set({line: linenumber.toString(), col: (colnumber + 1).toString()})
31
}
32
async function updateDom() {
33
await tick();
src/components/Content/Editor/scripts/Tabs.ts
+7
-2
@@ -4,13 +4,15 @@ import { loadFile } from '../../../FileTree/scripts/TreeData';
4
import CodeMirrorEditor from '../CodeMirrorEditor.svelte';
5
import { getLang, getLangMode } from './Editor';
6
export let tabs = writable([]);
7
-export let tabinfo = writable("");
7
+export let file_language = writable("");
8
+export let linefeed = writable("");
9
export let hidden = writable(true);
10
11
class Tab {
12
label: string;
13
path: string;
14
language: string = "Plain Text";
15
+ linefeed: string;
16
id: number;
17
active: boolean;
18
editor: CodeMirrorEditor | null;
@@ -31,6 +33,8 @@ class Tab {
33
extension = filepath.at(-1);
34
}
35
this.language = getLang(extension);
36
+
37
+ this.linefeed = file.linefeed;
38
39
let _ = undefined;
40
this.editor.$on("input", (e) => {
@@ -76,7 +80,8 @@ export function setActive(id) {
80
if (tab.id === id) {
81
activeid = id;
82
tab.active = true;
79
- tabinfo.set(tab.language);
83
+ file_language.set(tab.language);
84
+ linefeed.set(tab.linefeed);
85
tab.editor.focus();
86
}
87
else {
src/components/FileTree/scripts/TreeData.ts
+9
-2
@@ -15,9 +15,11 @@ class File {
15
filename: string;
16
path: string;
17
content: string;
18
- constructor(filename: string, path: string, content) {
18
+ linefeed: string;
19
+ constructor(filename: string, path: string, linefeed: string, content) {
20
this.filename = filename;
21
this.path = path;
22
+ this.linefeed = linefeed;
23
this.content = content;
24
}
25
}
@@ -25,7 +27,12 @@ export async function loadFile(path: string) {
27
if (path === null) return;
28
let filename = path.split(sep).pop();
29
let content = await readTextFile(path);
28
- return new File(filename, path, content);
30
+ let linefeed = getLF(content);
31
+ return new File(filename, path, linefeed, content);
32
+}
33
+
34
+function getLF(file) {
35
+ return file.includes('\r\n') ? 'CRLF' : 'LF'
36
}
37
38
async function loadTree() {
src/components/Footer/Footer.svelte
+6
-4
@@ -1,7 +1,7 @@
1
<script lang="ts">
2
import { Terminal } from "carbon-icons-svelte";
3
- import { hidden, tabinfo } from "../Content/Editor/scripts/Tabs";
4
- import { line_column } from "../Content/Editor/scripts/Editor";
3
+ import { hidden, file_language, linefeed } from "../Content/Editor/scripts/Tabs";
4
+ import { line_info } from "../Content/Editor/scripts/Editor";
5
import { invoke } from "@tauri-apps/api/tauri";
6
import { homeDir } from '@tauri-apps/api/path';
7
import { filetree } from "../FileTree/scripts/TreeStore";
@@ -25,8 +25,9 @@
25
</div>
26
{#if !$hidden}
27
<div id="codeinfo">
28
- <span>{$line_column.line} : {$line_column.col}</span>
29
- <span>{$tabinfo}</span>
28
+ <span title="End of Line Sequence">{$linefeed}</span>
29
+ <span>{$line_info.line} : {$line_info.col}</span>
30
+ <span>{$file_language}</span>
31
</div>
32
{/if}
33
</div>
@@ -51,6 +52,7 @@
52
justify-content: flex-end;
53
align-items: center;
54
flex-grow: 1;
55
+ font-size: 13px;
56
}
57
#tools {
58
display: flex;