From a2442650188d5cfe2b3ca763ab520f286500263e Mon Sep 17 00:00:00 2001
From: Catalin Mititiuc
Date: Mon, 20 Jan 2025 14:55:24 -0800
Subject: Handle renaming documents
---
lib/pandoc/watcher.ex | 14 ++++++++------
mix.exs | 2 +-
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/lib/pandoc/watcher.ex b/lib/pandoc/watcher.ex
index 9ff2620..515407c 100644
--- a/lib/pandoc/watcher.ex
+++ b/lib/pandoc/watcher.ex
@@ -3,6 +3,8 @@ defmodule Pandoc.Watcher do
use GenServer
+ @events MapSet.new([:closed, :deleted, :moved_from, :moved_to])
+
def start_link(args) do
GenServer.start_link(__MODULE__, args)
end
@@ -18,12 +20,8 @@ defmodule Pandoc.Watcher do
@impl true
def handle_info({:file_event, watcher_pid, {path, events}}, %{watcher_pid: watcher_pid} = state) do
- case {String.match?(path, state[:pattern]), :closed in events or :deleted in events} do
- {true, true} ->
- Pandoc.install_and_run(state[:profile], [Path.basename(path) | state[:extra_args]])
-
- _ ->
- nil
+ if String.match?(path, state[:pattern]) and update?(events) do
+ Pandoc.install_and_run(state[:profile], [Path.basename(path) | state[:extra_args]])
end
{:noreply, state}
@@ -32,4 +30,8 @@ defmodule Pandoc.Watcher do
def handle_info({:file_event, watcher_pid, :stop}, %{watcher_pid: watcher_pid} = state) do
{:noreply, state}
end
+
+ defp update?(events) do
+ events |> MapSet.new() |> MapSet.intersection(@events) |> MapSet.size() > 0
+ end
end
diff --git a/mix.exs b/mix.exs
index adb0ecf..3da4070 100644
--- a/mix.exs
+++ b/mix.exs
@@ -1,7 +1,7 @@
defmodule Pandoc.MixProject do
use Mix.Project
- @version "0.3.1"
+ @version "0.3.2"
@source_url "https://webdevcat.me/git/pandoc/"
def project do
--
cgit v1.2.3