rtfpessoa / diff2html

Pretty diff to html javascript library (diff2html)
https://diff2html.xyz
MIT License
2.8k stars 273 forks source link

How to remove the serial number of blank lines #481

Closed fengwei-ff closed 11 months ago

fengwei-ff commented 1 year ago

Step -1: Before filling an issue check out troubleshooting section

Step 0: Describe your environment

Step 1: Describe the problem:

Steps to reproduce:




diff example:

diff --git describe.c
index fabadb8,cc95eb0..4866510
"--- a/src/utils/request.ts\n+++ b/src/utils/request.ts\n@@ -9,40 +9,39 @@ export const useRequest = (\n   const [loading, setLoading] = useState<Boolean>(false);\n   const [err, serErr] = useState(false);\n   const [isClickSearch, setIsClickSearch] = useState(0);\n+  //临时存储请求此时\n+  const requestCount = useRef(0);\n   //用来存储默认参数\n   const defaultParams = useRef({});\n   const timerRef = useRef<any>();\n   const updatePayload = useRef<any>({});\n   const query = async (params: {}) => {\n     try {\n-      if (!Object.keys(params).length) return;\n       let res = await request({ ...defaultParams.current, ...params });\n-      //轮循终态\n-      const isRender = res[Object.keys(res)[0]][\n-        Object.keys(res[Object.keys(res)[0]]).filter(\n-          (item) => item !== \"PageInfo\"\n-        )[0]\n-      ].some((item: any) => item.Locked);\n-      if (isRender) {\n-        clearInterval(timerRef.current);\n-        setLoading(false);\n-        setIsClickSearch(0);\n-        return;\n-      }\n-      setIsClickSearch(0);\n-      updatePayload.current = params;\n+      requestCount.current++;\n       setLoading(false);\n+      updatePayload.current = params;\n       res = yd.dataKeyFirstLower(res) as IRequestInfo;\n+      setIsClickSearch(0);\n       setData(res);\n     } catch (err) {\n+      requestCount.current--;\n       clearInterval(timerRef.current);\n       setLoading(false);\n       serErr(true);\n     }\n   };\n   const deps = hasPolling\n-    ? [payload, request, query, err, isClickSearch]\n+    ? [payload, request, err, isClickSearch]\n     : [payload, request];\n+\n+  const pollingCondition = Boolean(\n+    payload.PageNo !== updatePayload.current.PageNo ||\n+      payload.PageSize !== updatePayload.current.PageSize ||\n+      Object.keys(payload).length !==\n+        Object.keys(updatePayload.current).length ||\n+      isClickSearch\n+  );\n   useEffect(() => {\n     clearInterval(timerRef.current);\n     if (err) {\n@@ -50,19 +49,11 @@ export const useRequest = (\n       setLoading(false);\n       return;\n     }\n-    if (\n-      payload.PageNo !== updatePayload.current.PageNo ||\n-      payload.PageSize !== updatePayload.current.PageSize ||\n-      Object.keys(payload).length !==\n-        Object.keys(updatePayload.current).length ||\n-      isClickSearch\n-    ) {\n+    if (pollingCondition) {\n       setLoading(true);\n     }\n     if (hasPolling && !isClickSearch) {\n-      timerRef.current = setInterval(() => {\n-        query(payload);\n-      }, 1500);\n+      timerRef.current = setInterval(() => query(payload), 2000);\n     } else {\n       query(payload);\n     }\n@@ -70,9 +61,23 @@ export const useRequest = (\n       clearInterval(timerRef.current);\n     };\n   }, deps);\n+\n+  if (requestCount.current > 4 && Object.keys(data)) {\n+    const isRender = (\n+      data[Object.keys(data)[0]][\n+        Object.keys(data[Object.keys(data)[0]]).filter(\n+          (item) => item !== \"pageInfo\"\n+        )[0]\n+      ] || []\n+    ).some((item: any) => item.locked);\n+    if (!isRender) {\n+      clearInterval(timerRef.current);\n+      requestCount.current = 0;\n+    }\n+  }\n   useEffect(() => {\n     query(payload);\n-  }, []);\n+  }, [payload]);\n   //点击搜索和重置  都需要loading效果\n   useEffect(() => {\n     setIsClickSearch(isClick!);\n"

image

Observed Results:

Expected Results:

Relevant Code:

// TODO(you): code here to reproduce the problem
fengwei-ff commented 1 year ago

image remove blank space

rtfpessoa commented 1 year ago

We do not do any magic with the diff, we just parse it and render the HTML. If you want to remove whitespace you can use for example --ignore-all-space in git before invoking diff2html.

rtfpessoa commented 11 months ago

Closing for inactivity.