Skip to content

Commit

Permalink
Drag-drop tags as text
Browse files Browse the repository at this point in the history
You can now drag tags from the tag pane and drop them in an editor as text.

(Also, added experimental support for using Tag Wrangler on mobile devices.)
  • Loading branch information
pjeby committed Nov 8, 2022
1 parent 50de622 commit 6637617
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Obsidian Tag Wrangler Plugin

> NEW in 0.5.5 - you can now drag tags from the tag pane to an editor pane to insert them as text.
This plugin adds a context menu for tags in the [Obsidian.md](https://obsidian.md) tag pane, with the following actions available:

![Image of tag wrangler's context menu](https://raw.githubusercontent.com/pjeby/tag-wrangler/master/contextmenu.png)
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"name": "Tag Wrangler",
"author": "PJ Eby",
"authorUrl": "https://github.com/pjeby",
"version": "0.5.4",
"version": "0.5.5",
"minAppVersion": "0.15.9",
"description": "Rename, merge, toggle, and search tags from the tag pane",
"isDesktopOnly": true
"isDesktopOnly": false
}
22 changes: 21 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,26 @@ export default class TagWrangler extends Plugin {
})
);


// Tag Drag
this.register(
onElement(document, "pointerdown", ".tag-pane-tag", (_, targetEl) => {
targetEl.draggable = "true";
}, {capture: true})
);
this.register(
onElement(document, "dragstart", ".tag-pane-tag", (event, targetEl) => {
const tagName = targetEl.find(".tag-pane-tag-text")?.textContent;
event.dataTransfer.setData("text/plain", "#"+tagName);
app.dragManager.onDragStart(event, {
source: "tag-wrangler",
type: "text",
title: tagName,
icon: "hashtag",
})
}, {capture: false})
);

// Track Tag Pages
const metaCache = this.app.metadataCache;
const plugin = this;
Expand Down Expand Up @@ -143,7 +163,7 @@ export default class TagWrangler extends Plugin {
onMenu(e, tagEl) {
if (!e.obsidian_contextmenu) {
e.obsidian_contextmenu = new Menu(this.app);
setImmediate(() => menu.showAtPosition({x: e.pageX, y: e.pageY}));
setTimeout(() => menu.showAtPosition({x: e.pageX, y: e.pageY}), 0);
}

const
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"0.5.4": "0.15.9",
"0.5.5": "0.15.9",
"0.5.3": "0.14.5",
"0.5.2": "0.13.19",
"0.4.6": "0.12.5",
Expand Down

0 comments on commit 6637617

Please sign in to comment.