dsh-ris-ide 1.8.6 → 1.8.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -3692,6 +3692,115 @@ window.__ModuleLoader__.load({
3692
3692
  return list
3693
3693
  }
3694
3694
 
3695
+ /**
3696
+ * `/a/b/` → `/a/b`; `/` stays `/` (the root itself is a legal selection).
3697
+ * @param {string} path - any path with optional trailing separators.
3698
+ * @returns {string} the path without trailing separators.
3699
+ */
3700
+ function trimPathSeparator(path) {
3701
+ var value = String(path === null || path === undefined ? '' : path)
3702
+ return value.length > 1 ? value.replace(/[\\/]+$/, '') : value
3703
+ }
3704
+
3705
+ /**
3706
+ * Whether `path` lies inside directory `ancestor` (both absolute).
3707
+ * Separator-agnostic: the tree speaks POSIX paths, a Windows host does not.
3708
+ * @param {string} path - candidate child.
3709
+ * @param {string} ancestor - directory.
3710
+ * @returns {boolean} true when `path` is below `ancestor`.
3711
+ */
3712
+ function isPathInside(path, ancestor) {
3713
+ var child = trimPathSeparator(path)
3714
+ var parent = trimPathSeparator(ancestor)
3715
+ if (child === '' || parent === '' || child === parent) return false
3716
+ return child.indexOf(parent + '/') === 0 || child.indexOf(parent + '\\') === 0
3717
+ }
3718
+
3719
+ /**
3720
+ * Reduce a selection to the rows a FILE command should act on.
3721
+ *
3722
+ * Expanding a folder selects its row too, so 「点开 A,再 Ctrl+点 a、b」 leaves
3723
+ * `[A, a, b]` selected. Acting on that literally moved A into the target and
3724
+ * then failed on A/a、A/b — the user saw 「整个 A 被剪切到 B」. A row that lies
3725
+ * INSIDE another selected row is already covered by it, and the descendant is
3726
+ * the one the user pointed at: keep descendants, drop the covering ancestor.
3727
+ * That direction also means 删除 acts on LESS than the raw selection, never
3728
+ * more.
3729
+ * @param {string[]} paths - selected absolute paths.
3730
+ * @returns {string[]} the list minus every path nested inside another one.
3731
+ */
3732
+ function narrowSelection(paths) {
3733
+ if (!Array.isArray(paths)) return []
3734
+ var unique = []
3735
+ for (var index = 0; index < paths.length; index += 1) {
3736
+ var value = trimPathSeparator(paths[index])
3737
+ if (value !== '' && unique.indexOf(value) === -1) unique.push(value)
3738
+ }
3739
+ var out = []
3740
+ for (var scan = 0; scan < unique.length; scan += 1) {
3741
+ // Drop a row when ANOTHER selected row lives inside it: the folder is
3742
+ // covered by the descendant the user pointed at, never the other way round.
3743
+ var covered = false
3744
+ for (var other = 0; other < unique.length; other += 1) {
3745
+ if (other !== scan && isPathInside(unique[other], unique[scan])) { covered = true; break }
3746
+ }
3747
+ if (!covered) out.push(unique[scan])
3748
+ }
3749
+ return out
3750
+ }
3751
+
3752
+ /**
3753
+ * Whether two path lists name exactly the same entries.
3754
+ * Paths are the only identity both sides share (a pasted File exposes no path,
3755
+ * the OS clipboard exposes no inode); order and trailing separators never matter.
3756
+ * @param {string[]} left - paths from one side.
3757
+ * @param {string[]} right - paths from the other side.
3758
+ * @returns {boolean} true when both list the same paths, once each.
3759
+ */
3760
+ function samePathSet(left, right) {
3761
+ if (!Array.isArray(left) || !Array.isArray(right) || left.length !== right.length) return false
3762
+ var mine = left.map(trimPathSeparator).sort()
3763
+ var theirs = right.map(trimPathSeparator).sort()
3764
+ for (var index = 0; index < mine.length; index += 1) {
3765
+ if (mine[index] !== theirs[index]) return false
3766
+ }
3767
+ return true
3768
+ }
3769
+
3770
+ /**
3771
+ * The ONE paste rule, as a pure decision so both gestures and the tests share it.
3772
+ *
3773
+ * The OS clipboard is the source of truth whenever it holds something: the
3774
+ * in-memory copy is a cache of the LAST tree copy, and pasting it after the
3775
+ * user copied something else is the 「粘出来的是上次那批」 bug.
3776
+ * Priority:
3777
+ * 1. `external` — the payload is not the tree's own copy: newer content wins.
3778
+ * 2. `import` — the Host read files the page could not deliver.
3779
+ * 3. `tree` — the Host read back exactly the tree's copy (keeps `cut`).
3780
+ * 4. `stale` — a text-only clipboard: drop the file copy held in memory.
3781
+ * 5. `tree` — nothing external readable: paste what the tree copied.
3782
+ * 6. `nothing` — there is nothing to paste at all.
3783
+ * @param {{delivered?: boolean, ownCopy?: boolean, hostFiles?: string[],
3784
+ * treePaths?: string[], hostText?: string, hasClipboard?: boolean}} state
3785
+ * @returns {'external'|'import'|'tree'|'stale'|'nothing'} what to do.
3786
+ */
3787
+ function pasteDecision(state) {
3788
+ var input = state === undefined || state === null ? {} : state
3789
+ var delivered = input.delivered === true
3790
+ var hostFiles = Array.isArray(input.hostFiles) ? input.hostFiles : []
3791
+ var treePaths = Array.isArray(input.treePaths) ? input.treePaths : []
3792
+ var hasClipboard = input.hasClipboard === true && treePaths.length > 0
3793
+ if (delivered && input.ownCopy !== true) return 'external'
3794
+ if (hostFiles.length > 0) {
3795
+ if (hasClipboard && samePathSet(hostFiles, treePaths)) return 'tree'
3796
+ return 'import'
3797
+ }
3798
+ var text = input.hostText === undefined || input.hostText === null ? '' : String(input.hostText)
3799
+ if (!delivered && text.trim() !== '') return 'stale'
3800
+ if (hasClipboard) return 'tree'
3801
+ return 'nothing'
3802
+ }
3803
+
3695
3804
  /** Colour kind of one tree entry (`dir` for folders, `dot` for dot-entries). */
3696
3805
  function fileKind(entry) {
3697
3806
  if (entry === null || entry === undefined) return 'other'
@@ -4624,6 +4733,24 @@ window.__ModuleLoader__.load({
4624
4733
  var [menuSub, setMenuSub] = useState(null)
4625
4734
  // Any open/close of the menu invalidates the flyout's anchor.
4626
4735
  useEffect(function () { setMenuSub(null) }, [treeMenu])
4736
+ // The context menu must know whether anything is pasteable BEFORE it paints:
4737
+ // 「粘贴」 used to be disabled for a desktop copy the tree never saw (the menu
4738
+ // only knew its in-memory clipboard). Read the Host clipboard as the menu
4739
+ // opens — cached ~2s, while a paste itself always reads fresh.
4740
+ useEffect(function () {
4741
+ if (treeMenu === null) {
4742
+ setOsPaste(function (prev) { return prev.state === 'idle' ? prev : { state: 'idle', count: 0 } })
4743
+ return undefined
4744
+ }
4745
+ var live = true
4746
+ setOsPaste({ state: 'loading', count: 0 })
4747
+ void readHostClipboardCached().then(function (host) {
4748
+ if (live !== true) return
4749
+ var count = host !== null && Array.isArray(host.files) ? host.files.length : 0
4750
+ setOsPaste({ state: count > 0 ? 'files' : 'empty', count: count })
4751
+ })
4752
+ return function () { live = false }
4753
+ }, [treeMenu])
4627
4754
  /** Pending creation dialog: `{mode:'file'|'dir', dir, ext?, title}`. */
4628
4755
  var [prompt, setPrompt] = useState(null)
4629
4756
  var [promptName, setPromptName] = useState('')
@@ -4672,6 +4799,18 @@ window.__ModuleLoader__.load({
4672
4799
  * cannot see the OS clipboard, so it waits one beat for this and only falls
4673
4800
  * back to the tree's own clipboard when no paste event arrived at all. */
4674
4801
  var pasteAtRef = useRef(0)
4802
+ /** Dedupe for clipboard complaints the Host repeats on every read. */
4803
+ var warnedClipboardRef = useRef({})
4804
+ /** `{at, value}` cache of the Host clipboard read (menu availability only). */
4805
+ var hostClipboardRef = useRef(null)
4806
+ /**
4807
+ * What the OS clipboard holds on its own, as far as the Host can tell:
4808
+ * `{state: 'idle'|'loading'|'files'|'empty', count}`. Only the context menu
4809
+ * uses it — 「粘贴」 must be enabled when the clipboard has files even though
4810
+ * the tree never copied anything (desktop → tree). Ctrl+V needs no such hint:
4811
+ * the paste event carries the answer.
4812
+ */
4813
+ var [osPaste, setOsPaste] = useState({ state: 'idle', count: 0 })
4675
4814
 
4676
4815
  /** The parent folder of a path (the tree only needs string maths). */
4677
4816
  function parentOf(path) {
@@ -4713,6 +4852,99 @@ window.__ModuleLoader__.load({
4713
4852
  if (selectedPaths.indexOf(path) !== -1) return selectedPaths.slice()
4714
4853
  return [path]
4715
4854
  }
4855
+ /** The module-level rule ({@link narrowSelection}), bound for local callers. */
4856
+ function normalizeSelection(paths) {
4857
+ return narrowSelection(paths)
4858
+ }
4859
+ /** Toast explaining that a covering ancestor was skipped by normalization. */
4860
+ function noteNormalizedSelection(raw, kept) {
4861
+ if (kept.length >= raw.length) return
4862
+ notify('已忽略同时选中的上级目录:只处理选中的 ' + kept.length + ' 项')
4863
+ }
4864
+ // Drag auto-scroll: the live pointer and the rAF id.
4865
+ // A tree can be much taller than its viewport, and HTML5 drag events only
4866
+ // fire on pointer movement — without this the user cannot drop on a folder
4867
+ // that is scrolled out of view.
4868
+ var dragPointRef = useRef(null)
4869
+ var dragFrameRef = useRef(0)
4870
+ /**
4871
+ * Pixels per frame for a pointer this close to the edge (2 at the rim, 18 inside).
4872
+ * Capped: a pointer dragged past the list edge would otherwise scroll by leaps.
4873
+ */
4874
+ function dragEdgeStep(distance, edge) {
4875
+ if (distance >= edge) return 0
4876
+ var ratio = 1 - Math.max(0, distance) / edge
4877
+ return Math.max(2, Math.min(18, Math.round(ratio * 18)))
4878
+ }
4879
+ /**
4880
+ * Row currently sitting at `y` (list-relative content coordinates), via its
4881
+ * vertical midpoint: the DROP TARGET during a scroll is whatever row the
4882
+ * pointer has been carried over, exactly like hovering it.
4883
+ * @param {HTMLElement} list - the scrolling tree container.
4884
+ * @param {number} y - content-space y (scrollTop + pointer offset).
4885
+ * @returns {string} the row path, or '' when the tree has no rows.
4886
+ */
4887
+ function rowAtEdge(list, y) {
4888
+ var rows = list.querySelectorAll('[data-tree-path]')
4889
+ if (rows.length === 0) return ''
4890
+ // Rect maths, not offsetTop: a row's offsetParent is the nearest positioned
4891
+ // ancestor, which is not guaranteed to be the scroller itself.
4892
+ var box = list.getBoundingClientRect()
4893
+ var chosen = rows[0]
4894
+ for (var index = 0; index < rows.length; index += 1) {
4895
+ var rect = rows[index].getBoundingClientRect()
4896
+ if (rect.top + rect.height / 2 - box.top + list.scrollTop > y) break
4897
+ chosen = rows[index]
4898
+ }
4899
+ return chosen.getAttribute('data-tree-path') || ''
4900
+ }
4901
+ /** One auto-scroll frame: scroll near the edges and move the drop target with it. */
4902
+ function runDragAutoScroll() {
4903
+ dragFrameRef.current = 0
4904
+ var list = treeListRef.current
4905
+ var point = dragPointRef.current
4906
+ if (list === null || list === undefined || point === null) return
4907
+ var box = list.getBoundingClientRect()
4908
+ var edge = Math.min(56, Math.max(20, Math.round(box.height / 5)))
4909
+ var fromTop = point.y - box.top
4910
+ var fromBottom = box.bottom - point.y
4911
+ var maxTop = Math.max(0, list.scrollHeight - box.height)
4912
+ var delta = 0
4913
+ if (fromTop < edge && list.scrollTop > 0) delta = -dragEdgeStep(fromTop, edge)
4914
+ else if (fromBottom < edge && list.scrollTop < maxTop - 1) delta = dragEdgeStep(fromBottom, edge)
4915
+ if (delta === 0) return
4916
+ // The scroll watchdog snaps back any scrollTop it cannot attribute to the
4917
+ // user (see the [lastGoodTop] effect): a drag has no pointerdown to vouch
4918
+ // for it, so each frame claims user input and moves the baseline too.
4919
+ markUserInput()
4920
+ list.scrollTop = Math.max(0, Math.min(maxTop, list.scrollTop + delta))
4921
+ rememberTop(list.scrollTop)
4922
+ // The row under the pointer moves with the scroll: keep the drop target on
4923
+ // it, so releasing after scrolling lands in the folder that scrolled in.
4924
+ var rowPath = rowAtEdge(list, list.scrollTop + fromTop)
4925
+ if (rowPath !== '' && dropTarget !== rowPath) setDropTarget(rowPath)
4926
+ dragFrameRef.current = requestAnimationFrame(runDragAutoScroll)
4927
+ }
4928
+ /**
4929
+ * Track the pointer of a live drag and keep the auto-scroll loop running.
4930
+ * @param {DragEvent} event - a dragover from the tree (row or container).
4931
+ */
4932
+ function armDragAutoScroll(event) {
4933
+ if (dragPointRef.current === null) dragPointRef.current = { y: event.clientY }
4934
+ else dragPointRef.current.y = event.clientY
4935
+ if (dragFrameRef.current === 0) dragFrameRef.current = requestAnimationFrame(runDragAutoScroll)
4936
+ }
4937
+ /** Stop the auto-scroll loop (drop, dragleave, dragend, unmount). */
4938
+ function stopDragAutoScroll() {
4939
+ dragPointRef.current = null
4940
+ if (dragFrameRef.current !== 0) {
4941
+ cancelAnimationFrame(dragFrameRef.current)
4942
+ dragFrameRef.current = 0
4943
+ }
4944
+ }
4945
+ useEffect(function () {
4946
+ return function () { stopDragAutoScroll() }
4947
+ }, [])
4716
4948
  function notify(message) {
4717
4949
  if (props !== null && props !== undefined && typeof props.onNote === 'function') props.onNote(message)
4718
4950
  }
@@ -5119,10 +5351,16 @@ window.__ModuleLoader__.load({
5119
5351
  * @param {'copy'|'cut'} mode - clipboard mode.
5120
5352
  */
5121
5353
  function beginCopy(mode) {
5122
- var seed = treeMenu !== null && treeMenu.entry !== null && treeMenu.entry !== undefined
5123
- ? treeMenu.entry.path
5124
- : (selectedPath === null ? '' : selectedPath)
5125
- var paths = selectionFor(seed)
5354
+ // ONE seed for both entry points: the menu already re-targeted the
5355
+ // selection on right-click, so reading treeMenu.entry.path here as well
5356
+ // only created a second rule that could drift from the keyboard's.
5357
+ var seed = selectedPath === null ? '' : selectedPath
5358
+ var picked = selectionFor(seed)
5359
+ var paths = normalizeSelection(picked)
5360
+ if (paths.length === 0) {
5361
+ setTreeMenu(null)
5362
+ return
5363
+ }
5126
5364
  var items = []
5127
5365
  for (var index = 0; index < paths.length; index += 1) {
5128
5366
  var entry = findEntry(paths[index])
@@ -5130,6 +5368,7 @@ window.__ModuleLoader__.load({
5130
5368
  }
5131
5369
  setTreeMenu(null)
5132
5370
  if (items.length === 0) return
5371
+ noteNormalizedSelection(picked, paths)
5133
5372
  setClipboard({ mode: mode, items: items })
5134
5373
  notify((mode === 'copy' ? '已复制 ' : '已剪切 ') + (items.length > 1 ? items.length + ' 项' : '「' + items[0].name + '」'))
5135
5374
  // The tree's own Ctrl+V reads the in-memory clipboard; ALSO publishing the
@@ -5639,96 +5878,78 @@ window.__ModuleLoader__.load({
5639
5878
  try { text = transfer.getData('text/uri-list') || '' } catch { text = '' }
5640
5879
  if (text.trim() === '') { try { text = transfer.getData('text/plain') || '' } catch { text = '' } }
5641
5880
  var paths = text.trim() === '' ? [] : parseClipboardPaths(text)
5642
- // The tree handles the gesture either way: it owns the destination.
5643
- event.preventDefault()
5881
+ var dir = pasteTargetDir()
5644
5882
  if (files.length > 0 || paths.length > 0) {
5645
- void pasteTreePayload(files, paths)
5883
+ // The tree owns the destination: a FILE payload is consumed here.
5884
+ event.preventDefault()
5885
+ void pasteResolved(dir, { files: files, paths: paths }, false)
5646
5886
  return
5647
5887
  }
5648
5888
  // EMPTY payload: in WSL a file copy made in Explorer never reaches the page
5649
- // (the Windows CF_HDROP flavour is not bridged into Chromium), so the Host —
5650
- // which can read the OS clipboard — has the final say.
5651
- void pasteFromOsClipboard(text)
5889
+ // (the Windows CF_HDROP flavour is not bridged into Chromium), and on any
5890
+ // desktop the Host may see flavours the page cannot. Ask the Host — but do
5891
+ // NOT preventDefault: an ordinary text paste is not the tree's business.
5892
+ void pasteResolved(dir, null, false)
5652
5893
  }
5653
5894
 
5654
5895
  /**
5655
- * Paste content the browser DID deliver, deciding where it came from.
5896
+ * The ONE paste rule, shared by the context menu and by Ctrl/Cmd+V.
5656
5897
  *
5657
- * `beginCopy` publishes the tree's selection to the OS clipboard too, so our
5658
- * own copy comes back looking exactly like external content. Matching names
5659
- * are not proof on WSL (a desktop copy of same-named files looks identical),
5660
- * so the Host's reading of the clipboard settles it: the same paths mean the
5661
- * tree's own copy (keep cut = move); anything else is NEWER content.
5662
- * @param {File[]} files - blobs from the paste payload.
5663
- * @param {string[]} paths - paths parsed from the payload text.
5664
- */
5665
- async function pasteTreePayload(files, paths) {
5666
- if (clipboard !== null && isTreeClipboardCopy(files, paths)) {
5667
- var host = await readHostClipboard()
5668
- if (host === null || host.files.length === 0 || samePathList(host.files, clipboardItems())) {
5669
- void pasteInto(pasteTargetDir())
5670
- return
5671
- }
5672
- }
5673
- // Different files than the tree copied — or the same names now pointing at a
5674
- // NEWER location: the newer clipboard wins, the in-memory copy is dropped.
5675
- if (clipboard !== null) setClipboard(null)
5676
- void importExternal(pasteTargetDir(), files, paths)
5677
- }
5678
-
5679
- /**
5680
- * Paste when the payload is empty but the SYSTEM clipboard may still hold a
5681
- * file list the page cannot see (WSL: Explorer → tree).
5682
- * @param {string} text - the (usually empty) payload text flavour.
5898
+ * Both gestures end here so they can never disagree again. Priority:
5899
+ * 1. A payload that is NOT the tree's own copy → newer external content.
5900
+ * 2. The Host reads back exactly the tree's copy → tree paste (keeps `cut`).
5901
+ * 3. The Host holds files the page could not deliver → import, drop the tree copy.
5902
+ * 4. Nothing file-shaped: a stale in-memory copy, or 「nothing to paste」.
5903
+ * @param {string} dir - destination directory (absolute).
5904
+ * @param {{files: File[], paths: string[]}|null} payload - what the paste event
5905
+ * delivered; null when the page delivered nothing (menu, invisible OS clipboard).
5906
+ * @param {boolean} announce - whether 「nothing to paste」 deserves a toast.
5683
5907
  */
5684
- async function pasteFromOsClipboard(text) {
5908
+ async function pasteResolved(dir, payload, announce) {
5685
5909
  var host = await readHostClipboard()
5686
- if (host !== null && host.files.length > 0) {
5687
- if (clipboard !== null && samePathList(host.files, clipboardItems())) {
5688
- // The tree's own copy is still what the OS clipboard carries.
5689
- void pasteInto(pasteTargetDir())
5690
- return
5691
- }
5692
- // Fresh files from the OS: a stale in-memory copy must not resurface them.
5693
- if (clipboard !== null) setClipboard(null)
5694
- void importExternal(pasteTargetDir(), [], host.files)
5910
+ var treeItems = clipboard !== null ? clipboardItems() : []
5911
+ var files = payload === null ? [] : payload.files
5912
+ var paths = payload === null ? [] : payload.paths
5913
+ var delivered = files.length > 0 || paths.length > 0
5914
+ var plan = pasteDecision({
5915
+ delivered: delivered,
5916
+ ownCopy: delivered && treeItems.length > 0 && isTreeClipboardCopy(files, paths),
5917
+ hostFiles: host !== null ? host.files : [],
5918
+ treePaths: treeItems.map(function (item) { return item.path }),
5919
+ hostText: host !== null ? host.text : '',
5920
+ hasClipboard: clipboard !== null,
5921
+ })
5922
+ if (plan === 'external') {
5923
+ pasteExternal(dir, files, paths)
5695
5924
  return
5696
5925
  }
5697
- if (clipboard === null) return
5698
- // Something that is not a file list sits on the OS clipboard (a text copy):
5699
- // the newer clipboard wins and the stale in-memory one is dropped.
5700
- var newer = text.trim() !== '' || (host !== null && host.text.trim() !== '')
5701
- if (newer) {
5702
- setClipboard(null)
5703
- notify('系统剪贴板里不是文件,已清空文件树里的旧复制')
5926
+ if (plan === 'import') {
5927
+ pasteExternal(dir, files, host.files)
5928
+ return
5929
+ }
5930
+ if (plan === 'tree') {
5931
+ void pasteInto(dir)
5704
5932
  return
5705
5933
  }
5706
- // No paste payload at all and nothing readable: the tree's own clipboard is
5707
- // the only thing there is to paste.
5708
- void pasteInto(pasteTargetDir())
5934
+ if (plan === 'stale') {
5935
+ if (clipboard !== null) {
5936
+ setClipboard(null)
5937
+ notify('系统剪贴板里不是文件,已清空文件树里的旧复制')
5938
+ } else if (announce === true) notify('剪贴板里没有可粘贴的文件')
5939
+ return
5940
+ }
5941
+ if (announce === true) notify('剪贴板里没有可粘贴的内容')
5709
5942
  }
5710
5943
 
5711
- /**
5712
- * Whether the OS clipboard holds exactly the entries the tree copied.
5713
- * Paths are the only identity both sides share.
5714
- * @param {string[]} files - paths the Host read back from the OS clipboard.
5715
- * @param {Array<{path: string}>} items - the tree's in-memory clipboard.
5716
- * @returns {boolean} true when both sides describe the same entries.
5717
- */
5718
- function samePathList(files, items) {
5719
- if (!Array.isArray(files) || files.length !== items.length) return false
5720
- var left = files.map(function (path) { return trimTrailingSeparator(path) }).sort()
5721
- var right = items.map(function (item) { return trimTrailingSeparator(item.path) }).sort()
5722
- for (var index = 0; index < left.length; index += 1) {
5723
- if (left[index] !== right[index]) return false
5724
- }
5725
- return true
5944
+ /** Import files the tree does not own; the stale in-memory copy is dropped. */
5945
+ function pasteExternal(dir, files, paths) {
5946
+ if (clipboard !== null) setClipboard(null)
5947
+ void importExternal(dir, files, paths)
5726
5948
  }
5727
5949
 
5728
- /** `/a/b/` → `/a/b`; `/` stays `/` (the root itself is a legal selection). */
5950
+ /** `/a/b/` → `/a/b`; `/` stays `/` (see {@link trimPathSeparator}). */
5729
5951
  function trimTrailingSeparator(path) {
5730
- var value = String(path === null || path === undefined ? '' : path)
5731
- return value.length > 1 ? value.replace(/[\\/]+$/, '') : value
5952
+ return trimPathSeparator(path)
5732
5953
  }
5733
5954
 
5734
5955
  /** The Host's reading of the OS clipboard, or null when it cannot read it. */
@@ -5738,20 +5959,49 @@ window.__ModuleLoader__.load({
5738
5959
  if (payload === null || payload === undefined || payload.ok !== true) return null
5739
5960
  // The host re-checks the ORIGINALS of the last tree copies: a source that
5740
5961
  // vanished after Ctrl+C is reported here, with its still-intact staged copy.
5962
+ // Opening a menu and pasting read this twice in a row — say each thing once.
5741
5963
  if (Array.isArray(payload.warnings)) {
5742
5964
  for (var warningIndex = 0; warningIndex < payload.warnings.length; warningIndex += 1) {
5743
- if (typeof payload.warnings[warningIndex] === 'string') notify(payload.warnings[warningIndex])
5965
+ if (typeof payload.warnings[warningIndex] === 'string') notifyClipboardOnce(payload.warnings[warningIndex])
5744
5966
  }
5745
5967
  }
5968
+ var missing = Array.isArray(payload.missing) ? payload.missing.filter(function (path) { return typeof path === 'string' }) : []
5969
+ if (missing.length > 0) notifyClipboardOnce('系统剪贴板里的 ' + missing.length + ' 个文件已不存在(可能已被移动或删除)')
5746
5970
  return {
5747
5971
  files: Array.isArray(payload.files) ? payload.files : [],
5748
5972
  text: typeof payload.text === 'string' ? payload.text : '',
5973
+ missing: missing,
5749
5974
  }
5750
5975
  } catch (problem) {
5751
5976
  return null
5752
5977
  }
5753
5978
  }
5754
5979
 
5980
+ /** Toast a clipboard complaint at most once per 5s (menus re-read constantly). */
5981
+ function notifyClipboardOnce(message) {
5982
+ var now = Date.now()
5983
+ var seen = warnedClipboardRef.current
5984
+ var last = seen[message]
5985
+ if (typeof last === 'number' && now - last < 5000) return
5986
+ seen[message] = now
5987
+ notify(message)
5988
+ }
5989
+
5990
+ /**
5991
+ * Host clipboard reading cached for ~2s — for UI that only needs to know
5992
+ * whether anything is pasteable (the 「粘贴」 menu item's enabled state).
5993
+ * A paste itself always reads fresh: the whole point is to see the newest
5994
+ * content, and a stale answer there would paste yesterday's selection.
5995
+ * @returns {Promise<object|null>} same shape as {@link readHostClipboard}.
5996
+ */
5997
+ async function readHostClipboardCached() {
5998
+ var cached = hostClipboardRef.current
5999
+ if (cached !== null && Date.now() - cached.at < 2000) return cached.value
6000
+ var value = await readHostClipboard()
6001
+ hostClipboardRef.current = { at: Date.now(), value: value }
6002
+ return value
6003
+ }
6004
+
5755
6005
  /**
5756
6006
  * Whether a `paste` payload is the tree's own clipboard coming back.
5757
6007
  *
@@ -6013,7 +6263,10 @@ window.__ModuleLoader__.load({
6013
6263
  }
6014
6264
  if (event.key === 'Delete') {
6015
6265
  event.preventDefault()
6016
- setPendingDelete(selectionFor(selectedPath).map(findEntry))
6266
+ var doomed = selectionFor(selectedPath)
6267
+ var target = normalizeSelection(doomed)
6268
+ noteNormalizedSelection(doomed, target)
6269
+ setPendingDelete(target.map(findEntry))
6017
6270
  return
6018
6271
  }
6019
6272
  if (meta && (event.key === 'z' || event.key === 'Z') && event.shiftKey !== true) {
@@ -6038,19 +6291,17 @@ window.__ModuleLoader__.load({
6038
6291
  return
6039
6292
  }
6040
6293
  if (meta && (event.key === 'v' || event.key === 'V')) {
6041
- // External content (OS files / file paths) has no tree clipboard;
6042
- // leave the key alone so the browser fires `paste` and
6043
- // `handleTreePaste` can import it. Only our own clipboard is ours.
6044
- if (clipboard === null) return
6045
6294
  // A text field owns Ctrl+V: a tree copy must not hijack typing.
6046
6295
  if (isTextEntry(event.target)) return
6047
- // The OS clipboard WINS whenever it carries files: only the `paste`
6048
- // event can see that, so never preventDefault here. An EMPTY OS
6049
- // clipboard fires no paste at all — wait one beat, then paste ours.
6296
+ // NEVER preventDefault: only the `paste` event can see the OS clipboard,
6297
+ // and `handleTreePaste` routes every source through `pasteResolved`, the
6298
+ // same rule the menu uses. When no paste event arrives at all (empty OS
6299
+ // clipboard, or a desktop that swallows the flavour) fall back once.
6050
6300
  var askedAt = Date.now()
6301
+ var target = pasteTargetDir()
6051
6302
  window.setTimeout(function () {
6052
6303
  if (pasteAtRef.current >= askedAt) return
6053
- void pasteInto(pasteTargetDir())
6304
+ void pasteResolved(target, null, false)
6054
6305
  }, 150)
6055
6306
  }
6056
6307
  }
@@ -6182,9 +6433,10 @@ window.__ModuleLoader__.load({
6182
6433
  'data-tree-drop': isDropTarget ? '1' : undefined,
6183
6434
  draggable: true,
6184
6435
  onDragStart: function (event) {
6185
- // Drag carries the whole selection when the grabbed row is part of it,
6186
- // so Ctrl+selected rows move together in one gesture.
6187
- var dragged = selectionFor(entry.path)
6436
+ // Drag carries the whole SELECTION when the grabbed row is part of it,
6437
+ // so Ctrl+selected rows move together in one gesture — normalized, so
6438
+ // a covering parent folder cannot travel along with its children.
6439
+ var dragged = normalizeSelection(selectionFor(entry.path))
6188
6440
  try {
6189
6441
  event.dataTransfer.setData('application/x-dsh-ris-ide-paths', JSON.stringify(dragged))
6190
6442
  event.dataTransfer.setData('text/plain', entry.path)
@@ -6198,14 +6450,17 @@ window.__ModuleLoader__.load({
6198
6450
  onDragOver: function (event) {
6199
6451
  event.preventDefault()
6200
6452
  try { event.dataTransfer.dropEffect = 'move' } catch { /* ignore */ }
6453
+ armDragAutoScroll(event)
6201
6454
  if (dropTarget !== entry.path) setDropTarget(entry.path)
6202
6455
  },
6203
6456
  onDragLeave: function () {
6204
6457
  if (dropTarget === entry.path) setDropTarget(null)
6205
6458
  },
6459
+ onDragEnd: function () { stopDragAutoScroll() },
6206
6460
  onDrop: function (event) {
6207
6461
  event.preventDefault()
6208
6462
  event.stopPropagation()
6463
+ stopDragAutoScroll()
6209
6464
  var external = []
6210
6465
  try { external = Array.prototype.slice.call(event.dataTransfer.files || []) } catch { external = [] }
6211
6466
  if (external.length > 0) {
@@ -6256,14 +6511,12 @@ window.__ModuleLoader__.load({
6256
6511
  },
6257
6512
  h('span', {
6258
6513
  style: Object.assign({}, S.treeTwist, entry.isDir === true ? { cursor: 'pointer' } : {}),
6259
- // The triangle only toggles; the row (name) also selects. Without the
6260
- // explicit stopPropagation the same click ran the row's handler too,
6261
- // which is what made the two click targets feel different.
6514
+ // The triangle only toggles: selecting the folder here too left
6515
+ // `[A, a, b]` selected after 「点开 A,再 Ctrl+点 a、b」, and a later
6516
+ // 剪切/删除 then acted on A as well. Selection stays the row's job.
6262
6517
  'data-tree-twisty': entry.isDir === true ? (open ? 'open' : 'closed') : undefined,
6263
- // Same outcome as clicking the row: select + expand/collapse. The
6264
- // stopPropagation only prevents the row handler running twice.
6265
6518
  onClick: entry.isDir === true
6266
- ? function (event) { event.stopPropagation(); selectOne(entry.path); toggle(entry) }
6519
+ ? function (event) { event.stopPropagation(); toggle(entry) }
6267
6520
  : undefined,
6268
6521
  }, entry.isDir ? (open ? '▾' : '▸') : ''),
6269
6522
  h('span', {
@@ -6313,6 +6566,16 @@ window.__ModuleLoader__.load({
6313
6566
  /** The row context menu (main list or the "new file" sub-list). */
6314
6567
  function renderTreeMenu() {
6315
6568
  if (treeMenu === null) return null
6569
+ // 「粘贴」 is enabled when EITHER side has something: the tree's in-memory
6570
+ // clipboard, or files the Host can see on the OS clipboard (desktop → tree,
6571
+ // which the menu used to call 「剪贴板为空」). Both entry points then run the
6572
+ // same pasteResolved(), so the menu never pastes something Ctrl+V would not.
6573
+ var canPaste = clipboard !== null || osPaste.state === 'files'
6574
+ var pasteTitle = clipboard !== null
6575
+ ? '粘贴 ' + clipboardLabel() + ' 到 ' + treeMenu.dir
6576
+ : (osPaste.state === 'files'
6577
+ ? '粘贴 ' + osPaste.count + ' 项(来自系统剪贴板)到 ' + treeMenu.dir
6578
+ : (osPaste.state === 'loading' ? '正在读取系统剪贴板…' : '剪贴板里没有可粘贴的内容'))
6316
6579
  var items
6317
6580
  {
6318
6581
  items = [
@@ -6346,14 +6609,13 @@ window.__ModuleLoader__.load({
6346
6609
  : null,
6347
6610
  h('button', {
6348
6611
  key: 'paste', type: 'button', 'data-tree-action': 'paste',
6349
- style: clipboard === null ? Object.assign({}, S.tabMenuItem, { opacity: 0.45 }) : S.tabMenuItem,
6350
- disabled: clipboard === null,
6351
- title: clipboard === null ? '剪贴板为空' : ('粘贴 ' + clipboardLabel() + ' 到 ' + treeMenu.dir),
6612
+ style: canPaste === true ? S.tabMenuItem : Object.assign({}, S.tabMenuItem, { opacity: 0.45 }),
6613
+ disabled: canPaste !== true,
6614
+ title: pasteTitle,
6352
6615
  onClick: function () {
6353
- if (clipboard === null) return
6354
6616
  var dir = treeMenu.dir
6355
6617
  setTreeMenu(null)
6356
- void pasteInto(dir)
6618
+ void pasteResolved(dir, null, true)
6357
6619
  },
6358
6620
  }, '粘贴'),
6359
6621
  h('button', {
@@ -6383,9 +6645,15 @@ window.__ModuleLoader__.load({
6383
6645
  title: selectedPaths.length > 1 ? '剪切所选 ' + selectedPaths.length + ' 项(Ctrl+X)' : '剪切(Ctrl+X)',
6384
6646
  onClick: function () { beginCopy('cut') },
6385
6647
  }, '剪切'),
6386
- h('button', { key: 'delete', type: 'button', style: S.tabMenuItem, 'data-tree-action': 'delete', title: selectionFor(treeMenu.entry.path).length > 1
6387
- ? '删除所选 ' + selectionFor(treeMenu.entry.path).length + ' 项(移到回收站,Ctrl+Z 撤销)'
6388
- : '删除(移到回收站,Ctrl+Z 撤销)', onClick: function () { setPendingDelete(selectionFor(treeMenu.entry.path).map(findEntry)); setTreeMenu(null) } }, '删除'),
6648
+ h('button', { key: 'delete', type: 'button', style: S.tabMenuItem, 'data-tree-action': 'delete', title: normalizeSelection(selectionFor(treeMenu.entry.path)).length > 1
6649
+ ? '删除所选 ' + normalizeSelection(selectionFor(treeMenu.entry.path)).length + ' 项(移到回收站,Ctrl+Z 撤销)'
6650
+ : '删除(移到回收站,Ctrl+Z 撤销)', onClick: function () {
6651
+ var doomed = selectionFor(treeMenu.entry.path)
6652
+ var target = normalizeSelection(doomed)
6653
+ noteNormalizedSelection(doomed, target)
6654
+ setPendingDelete(target.map(findEntry))
6655
+ setTreeMenu(null)
6656
+ } }, '删除'),
6389
6657
  h('button', {
6390
6658
  key: 'copy-name', type: 'button', style: S.tabMenuItem, 'data-tree-action': 'copy-name',
6391
6659
  onClick: function () {
@@ -6661,9 +6929,22 @@ window.__ModuleLoader__.load({
6661
6929
  tabIndex: -1,
6662
6930
  onClick: function () { setTreeMenu(null) },
6663
6931
  onPaste: handleTreePaste,
6664
- onDragOver: function (event) { event.preventDefault() },
6932
+ // Auto-scroll on the whole surface, not just rows: dragging past the last
6933
+ // row (or over the empty area under a short tree) must still scroll.
6934
+ onDragOver: function (event) {
6935
+ event.preventDefault()
6936
+ armDragAutoScroll(event)
6937
+ },
6938
+ onDragLeave: function (event) {
6939
+ var list = treeListRef.current
6940
+ if (list === null || list === undefined) { stopDragAutoScroll(); return }
6941
+ var next = event.relatedTarget
6942
+ if (next === null || next === undefined || list.contains(next) !== true) stopDragAutoScroll()
6943
+ },
6944
+ onDragEnd: function () { stopDragAutoScroll() },
6665
6945
  onDrop: function (event) {
6666
6946
  event.preventDefault()
6947
+ stopDragAutoScroll()
6667
6948
  var rootDir = absolutePath(cwd, activeRoot)
6668
6949
  var external = []
6669
6950
  try { external = Array.prototype.slice.call(event.dataTransfer.files || []) } catch { external = [] }
@@ -16144,6 +16425,13 @@ var [ui, setUi] = useState(function () {
16144
16425
  duplicateName: duplicateName,
16145
16426
  collisionCopyName: collisionCopyName,
16146
16427
  toggleTreeSelection: toggleTreeSelection,
16428
+ /** Selection normalization: a covering folder never travels with its children. */
16429
+ narrowSelection: narrowSelection,
16430
+ isPathInside: isPathInside,
16431
+ trimPathSeparator: trimPathSeparator,
16432
+ /** The single paste rule and its path identity: the whole matrix is testable. */
16433
+ pasteDecision: pasteDecision,
16434
+ samePathSet: samePathSet,
16147
16435
  helpSections: helpSections,
16148
16436
  ideIcon: ideIcon,
16149
16437
  ideBadgeIcon: ideBadgeIcon,