From 7909cf4067c25d8c171315517f2fd0a75958ea1f Mon Sep 17 00:00:00 2001
From: GyDi <zzzgydi@gmail.com>
Date: Sat, 14 Jan 2023 14:57:55 +0800
Subject: [PATCH] fix: adjust fields order

---
 src-tauri/src/enhance/field.rs                     | 14 +++++++-------
 src/components/setting/mods/clash-field-viewer.tsx | 13 ++-----------
 src/utils/clash-fields.ts                          |  8 ++++----
 3 files changed, 13 insertions(+), 22 deletions(-)

diff --git a/src-tauri/src/enhance/field.rs b/src-tauri/src/enhance/field.rs
index 94484fc..e6f5752 100644
--- a/src-tauri/src/enhance/field.rs
+++ b/src-tauri/src/enhance/field.rs
@@ -1,34 +1,34 @@
 use serde_yaml::{Mapping, Value};
 
 pub const HANDLE_FIELDS: [&str; 9] = [
+    "mode",
     "port",
     "socks-port",
     "mixed-port",
-    "mode",
-    "ipv6",
-    "log-level",
     "allow-lan",
-    "external-controller",
+    "log-level",
+    "ipv6",
     "secret",
+    "external-controller",
 ];
 
 pub const DEFAULT_FIELDS: [&str; 5] = [
     "proxies",
     "proxy-groups",
-    "rules",
     "proxy-providers",
+    "rules",
     "rule-providers",
 ];
 
 pub const OTHERS_FIELDS: [&str; 25] = [
-    "tun",
     "dns",
+    "tun",
     "ebpf",
     "hosts",
     "script",
     "profile",
     "payload",
-    "tunnels", // clash dev
+    "tunnels",
     "auto-redir",
     "experimental",
     "interface-name",
diff --git a/src/components/setting/mods/clash-field-viewer.tsx b/src/components/setting/mods/clash-field-viewer.tsx
index d9bc09e..8185cba 100644
--- a/src/components/setting/mods/clash-field-viewer.tsx
+++ b/src/components/setting/mods/clash-field-viewer.tsx
@@ -13,17 +13,8 @@ import { BaseDialog, DialogRef } from "@/components/base";
 import { useProfiles } from "@/hooks/use-profiles";
 import { Notice } from "@/components/base";
 
-const fieldSorter = (a: string, b: string) => {
-  if (a.includes("-") === a.includes("-")) {
-    if (a.length === b.length) return a.localeCompare(b);
-    return a.length - b.length;
-  } else if (a.includes("-")) return 1;
-  else if (b.includes("-")) return -1;
-  return 0;
-};
-
-const otherFields = [...OTHERS_FIELDS].sort(fieldSorter);
-const handleFields = [...HANDLE_FIELDS, ...DEFAULT_FIELDS].sort(fieldSorter);
+const otherFields = [...OTHERS_FIELDS];
+const handleFields = [...HANDLE_FIELDS, ...DEFAULT_FIELDS];
 
 export const ClashFieldViewer = forwardRef<DialogRef>((props, ref) => {
   const { t } = useTranslation();
diff --git a/src/utils/clash-fields.ts b/src/utils/clash-fields.ts
index ef2bb15..678d3a2 100644
--- a/src/utils/clash-fields.ts
+++ b/src/utils/clash-fields.ts
@@ -1,9 +1,9 @@
 export const HANDLE_FIELDS = [
+  "mode",
   "port",
   "socks-port",
   "mixed-port",
   "allow-lan",
-  "mode",
   "log-level",
   "ipv6",
   "secret",
@@ -11,22 +11,22 @@ export const HANDLE_FIELDS = [
 ];
 
 export const DEFAULT_FIELDS = [
-  "rules",
   "proxies",
   "proxy-groups",
   "proxy-providers",
+  "rules",
   "rule-providers",
 ] as const;
 
 export const OTHERS_FIELDS = [
-  "tun",
   "dns",
+  "tun",
   "ebpf",
   "hosts",
   "script",
   "profile",
   "payload",
-  "tunnels", // clash dev
+  "tunnels",
   "auto-redir",
   "experimental",
   "interface-name",
-- 
GitLab