aboutsummaryrefslogtreecommitdiff
path: root/Main.hs
diff options
context:
space:
mode:
authorMirek Kratochvil <exa.exa@gmail.com>2025-07-13 10:24:23 +0200
committerMirek Kratochvil <exa.exa@gmail.com>2025-07-13 10:24:23 +0200
commitbc5d7a6915af2774f17f31641ed249d20311f9ee (patch)
treee0615bfd375c20ba3bf4eaa436a216aeb8eb3722 /Main.hs
parent96a623ac0766df9d6427419c1c8a8e799798d825 (diff)
downloadwerge-bc5d7a6915af2774f17f31641ed249d20311f9ee.tar.gz
werge-bc5d7a6915af2774f17f31641ed249d20311f9ee.tar.bz2
fine-grained space merging
Diffstat (limited to 'Main.hs')
-rw-r--r--Main.hs20
1 files changed, 19 insertions, 1 deletions
diff --git a/Main.hs b/Main.hs
index dd2f35f..c7701b1 100644
--- a/Main.hs
+++ b/Main.hs
@@ -112,13 +112,31 @@ zeal (Conflict m o y) =
pops ms ys = ((ms, ys), [])
zeal x = [x]
-resolve Config {..} c@(Conflict m o y)
+resolve cfg@Config {..} c@(Conflict m o y)
+ | all Toks.space (concat [m, o, y]) && cfgSpaces /= SpacesNormal =
+ resolveSpace cfg c
| m == o && o == y = Ok o
| m == o && cfgResolveSeparate = Ok y
| o == y && cfgResolveSeparate = Ok m
| m == y && cfgResolveOverlaps = Ok m
resolve _ x = x
+-- TODO: there might be a bit of interplay between the spaces handling and
+-- separate/overlapped conflict resolution -- e.g., what if someone wants to
+-- merge overlapping edits in text but separate edits in spaces? At this point
+-- that might be ignorable.
+resolveSpace Config {..} c@(Conflict m o y)
+ | m == o && o == y = Ok o
+ | otherwise =
+ case cfgSpaces of
+ SpacesConflict -> c
+ SpacesMy -> Ok m
+ SpacesOld -> Ok o
+ SpacesYour -> Ok y
+ _ -> error "spaces resolution failed"
+
+resolveSpaces _ x = x
+
merge cfg@Config {..} ms ys =
regroup
. map (resolve cfg)