Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes. #47

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 37 additions & 8 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,19 @@ struct Child {
path: String,
}

#[cfg(target_os = "windows")]
lazy_static! {
static ref PATH: Mutex<String> =
Mutex::new("C:/Users/User/Documents/GitHub/text-editor/Folder".to_string());
static ref PATH: Mutex<String> = Mutex::new("%USERPROFILE%/Desktop".to_string());
GoldenWRaft marked this conversation as resolved.
Show resolved Hide resolved
}

#[cfg(target_os = "linux")]
lazy_static! {
static ref PATH: Mutex<String> = Mutex::new("~/Desktop".to_string());
}

#[cfg(target_os = "macos")]
lazy_static! {
static ref PATH: Mutex<String> = Mutex::new("~/Desktop".to_string());
}

#[tauri::command]
Expand Down Expand Up @@ -72,15 +82,18 @@ fn save_config() {

#[tauri::command]
fn delete_file(path: String) -> u8 {
delete_child(&path.replace(".md", ""));
update_opened(path.clone(), false);

let path = PathBuf::from(PATH.lock().unwrap().clone()).join(path);

let _ = fs::remove_file(&path);

println!("Removed file: {:?}", path);
if path.to_str().unwrap().contains("Untitled") {
let _ = fs::remove_file(&path).unwrap_or_else(|error| {
println!("Failed to remove file: {:?}", error);
});

return 0;
return 0;
GoldenWRaft marked this conversation as resolved.
Show resolved Hide resolved
}
return 1;
}

#[tauri::command]
Expand Down Expand Up @@ -193,6 +206,8 @@ fn get_theme() -> String {

#[tauri::command]
fn delete_child(path: &str) {
delete_file(format!("{}.md", path));

let json_path: PathBuf = PathBuf::from(PATH.lock().unwrap().clone()).join("config.json");
let contents = fs::read_to_string(&json_path).expect("Failed to read configuration.");

Expand Down Expand Up @@ -271,6 +286,7 @@ fn update_opened(path: String, add: bool) -> Value {
let mut json_contents: Value = serde_json::from_str(&contents).expect("Failed to parse JSON");

let mut opened = json_contents["opened"].clone();
let mut children = json_contents["children"].clone();

if add {
let id = &Value::String(child_id.clone());
Expand All @@ -286,11 +302,20 @@ fn update_opened(path: String, add: bool) -> Value {
}
} else {
if let Some(array) = opened.as_array_mut() {
array.retain(|x| x.as_str() != Some(&child_id));
array.retain(|x| {
return x.as_str() != Some(&child_id);
});
}

if let Some(child_array) = children.as_array_mut() {
child_array.retain(|x| {
return x["id"].as_str() != Some(&child_id);
});
}
}

json_contents["opened"] = opened.clone();
json_contents["children"] = children.clone();

// Serialize the modified JSON back to a string
let updated_json =
Expand Down Expand Up @@ -318,6 +343,10 @@ fn save_title(old_path: String, new_path: String) {
let old_path_buf = PathBuf::from(PATH.lock().unwrap().clone()).join(&old_path);
let new_path_buf = PathBuf::from(PATH.lock().unwrap().clone()).join(&new_path);

if old_path == new_path {
return;
}

let path = PathBuf::from(PATH.lock().unwrap().clone()).join("config.json");
let contents =
String::from_utf8_lossy(&fs::read(&path).expect("Failed to read configuration."))
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"resizable": true,
"title": "Fextify",
"width": 1920,
"height": 1080
"height": 1080,
"maximized": true
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion src/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ async function ask_for_file() {
const result = await tauri.dialog.open({
title: "Choose a file to open.",
multiple: false,
defaultPath: 'C:/Users/User/Documents/GitHub/text-editor/Folder/',
// Not working
//defaultPath: 'C:/Users/User/Documents/GitHub/text-editor/Folder/',
filters: [
{
name: 'Markdown',
Expand Down
111 changes: 6 additions & 105 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
<title>Fextify</title>
<script type="module" src="/main.js" defer></script>

<script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4="
crossorigin="anonymous"></script>
<script src="jquery-3.7.1.min.js"></script>

<script src="https://unpkg.com/@popperjs/core@2"></script>
<script src="https://unpkg.com/tippy.js@6"></script>
<script src="popper.min.js"></script>
<script src="tippy-bundle.umd.min.js"></script>

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/toastify-js"></script>
<script type="text/javascript" src="toastify-js.js"></script>

<script src="./ckeditor.js"></script>

Expand All @@ -42,7 +41,7 @@
<div id="cssStyling" style="display: none">
<h1>Themes</h1>

<div id="cssGrid">
<div id="cssGrid" style="overflow-x: auto;">
<div class="theme" style="background-color: #0f0f0f; color: white;" onclick="changeTheme('/themes/default.css')">Default</div>
<div class="theme" style="background-color: #e8e1d2; color: #0f0f0f;" onclick="changeTheme('/themes/coffee.css')">Coffee</div>
</div>
Expand All @@ -60,105 +59,7 @@ <h1>Themes</h1>
<div class="results" id="suggestionContainer">
<!-- Suggestions will be displayed here -->
<ul class="list" id="suggestionList">
<li>
<div class="suggestion">
<div class="left-content">
<span>Close current file</span>
</div>
<div class="right-content">
<kbd>Ctrl</kbd><span> + </span><kbd>W</kbd>
</div>
</div>
</li>

<li>
<div class="suggestion">
<div class="left-content">
<span>Open file</span>
</div>
<div class="right-content">
<kbd>Ctrl</kbd><span> + </span><kbd>O</kbd>
</div>
</div>
</li>

<li>
<div class="suggestion">
<div class="left-content">
<span>Switch file (quick)</span>
</div>
<div class="right-content">
<kbd>Ctrl</kbd><span> + </span><kbd>Tab</kbd>
</div>
</div>
</li>

<li>
<div class="suggestion">
<div class="left-content">
<span>Switch focus</span>
</div>
<div class="right-content">
<kbd>Tab</kbd>
</div>
</div>
</li>

<li>
<div class="suggestion">
<div class="left-content">
<span>Switch file</span>
</div>
<div class="right-content">
<kbd>Ctrl</kbd><span> + </span><kbd>1-9</kbd>
</div>
</div>
</li>

<li>
<div class="suggestion">
<div class="left-content">
<span>New file</span>
</div>
<div class="right-content">
<kbd>Ctrl</kbd><span> + </span><kbd>N</kbd>
</div>
</div>
</li>

<li>
<div class="suggestion">
<div class="left-content">
<span>Command pallet</span>
</div>
<div class="right-content">
<kbd>Ctrl</kbd><span> + </span><kbd>P</kbd>
</div>
</div>
</li>

<li>
<div class="suggestion">
<div class="left-content">
<span>Copy HTML output</span>
</div>
<div class="right-content">
<kbd>Ctrl</kbd><span> + </span><kbd>Shift</kbd><span> + </span><kbd>H</kbd>
</div>
</div>
</li>

<li>
<div class="suggestion">
<div class="left-content">
<span>Change theme</span>
</div>
<div class="right-content">
<kbd>Ctrl</kbd><span> + </span><kbd>Alt</kbd><span> + </span><kbd>S</kbd>
</div>
</div>
</li>

<!-- Data will render here -->
</ul>
</div>

Expand Down
2 changes: 2 additions & 0 deletions src/jquery-3.7.1.min.js

Large diffs are not rendered by default.

Loading