Skip to content

Commit

Permalink
Merge branch 'release/v0.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveryh committed May 3, 2023
2 parents dbbae31 + b80f64a commit be3eab4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-emoji-toolbar",
"name": "Emoji Toolbar",
"version": "0.4.0",
"version": "0.4.1",
"description": "Quickly search for and insert emojis into your notes.",
"author": "oliveryh",
"authorUrl": "https://github.com/oliveryh/obsidian-emoji-toolbar",
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-emoji-toolbar",
"version": "0.4.0",
"version": "0.4.1",
"description": "Quickly search for an insert emojis into your editor.",
"repository": {
"type": "git",
Expand Down
20 changes: 15 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, MarkdownPostProcessor, MarkdownPreviewRenderer, Modal, Notice, Plugin, PluginSettingTab, Setting } from "obsidian";
import { App, MarkdownPostProcessor, MarkdownPreviewRenderer, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, Editor } from "obsidian";
import React from "react";
import ReactDOM from "react-dom";
import twemoji from 'twemoji'
Expand All @@ -10,17 +10,25 @@ function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms || DEF_DELAY));
}

function insertText(editor: Editor, text: string) {
if (text.length === 0 || text==null) return
const cursor = editor.getCursor('from')
editor.replaceRange(text, cursor, cursor)
app.commands.executeCommandById("editor:focus")
app.workspace.activeLeaf.view.editor.exec("goRight")
}

class EmojiModal extends Modal {
private div: HTMLElement;
private reactComponent: React.ReactElement;

constructor(app: App, theme: str, isNative: boolean) {
constructor(app: App, theme: str, isNative: boolean, editor: Editor) {
super(app)
this.reactComponent = React.createElement(EmojiToolbar, {
"onSelect": async (emoji: any) => {
"onSelect": async (emoji) => {
this.close()
await sleep(10)
document.execCommand('insertText', false, emoji.native)
insertText(editor, emoji.native)
},
"onClose": () => {
this.close()
Expand Down Expand Up @@ -82,7 +90,9 @@ export default class EmojiPickerPlugin extends Plugin {
try {
const theme = this.app.getTheme() === 'moonstone' ? 'light' : 'dark'
const isNative = !this.settings.twitterEmojiActive
const myModal = new EmojiModal(this.app, theme, isNative);
const view = this.app.workspace.getActiveViewOfType(MarkdownView)
if (!view){ return }
const myModal = new EmojiModal(this.app, theme, isNative, view.editor)
myModal.open()
document.getElementsByClassName("emoji-mart-search")[0].getElementsByTagName('input')[0].focus()
document.getElementsByClassName("emoji-mart-search")[0].getElementsByTagName('input')[0].select()
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"0.3.0": "0.10.11",
"0.3.1": "0.10.11",
"0.3.2": "0.16.3",
"0.4.0": "0.16.3"
"0.4.0": "0.16.3",
"0.4.1": "0.16.3"
}

0 comments on commit be3eab4

Please sign in to comment.