Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use plugin as a simple cursor replacement #3

Open
ronrdev opened this issue Aug 30, 2022 · 15 comments
Open

Add option to use plugin as a simple cursor replacement #3

ronrdev opened this issue Aug 30, 2022 · 15 comments

Comments

@ronrdev
Copy link

ronrdev commented Aug 30, 2022

Since obsidian switched to using the system cursor a plugin is needed to add back an optional styled cursor. I personally like the fat blue cursor of iAwriter.

Option to go back to a custom cursor in Obsidian.
Option to turn off cursor movement effects. (As cool as they are :)

Adding an image from iAwriter just to show how the prominent cursor fits with the intention of this plugin.
iA Writer 01

@vrtmrz
Copy link
Owner

vrtmrz commented Aug 30, 2022

Thank you for asking me!
Ninja-cursor can turn into as like that, by CSS-snippet.

Like this:

/* iAWriter-ish style. */
.cursorWrapper .x-cursor {
    opacity: 1;
    background: #00bbff;
    width: 3px;
    left: -1px;
    top: -6px;
    height: calc(12px + var(--cursor-height));
    transition: opacity;
}

/* Disable movement effect */
.cursorWrapper .x-cursor::after {
    display: none;
}

/* Blinking */
.cursorWrapper .x-cursor0,
.cursorWrapper .x-cursor1 {
    animation: blink1 1s 0s both infinite;
}

@keyframes blink1 {
    0% {
        opacity: 1;
    }

    45% {
        opacity: 1;
    }

    50% {
        opacity: 0.2;
    }

    95% {
        opacity: 0;
    }

    100% {
        opacity: 0.2;
    }
}

Could you please try this CSS snippet?

@ronrdev
Copy link
Author

ronrdev commented Aug 30, 2022

Hello. Thanks for sharing the snippet. It works well enough for me.

I don't know if there is a way to make it more responsive. Just want to report two issues. The custom cursor does not follow scroll position, and it is slower to respond than the system cursor after typing each letter. I will have to comment out the blink because the system cursor is still visible causing distraction.

ninja-2022-08-30_14.05.15.mp4

Also noticed this glitch. I understand this is just a fun plugin, so I can live with the issues.

ninja2-2022-08-30_14.31.16.mp4

Thanks again. Having a more prominent cursor helps me

@vrtmrz
Copy link
Owner

vrtmrz commented Aug 31, 2022

@ronrdev
The scrolling issue is fixed at v0.0.5!
And I am going to investigate the delay of cursor movement.

@ronrdev
Copy link
Author

ronrdev commented Aug 31, 2022

Awesome!
Also would it be possible to have different settings/css for light and dark mode? I can create a new issue if this is something you would like to add to the plugin. I just want to change the color, but people might want a toggle/different effects for light and dark mode as well.

@ronrdev
Copy link
Author

ronrdev commented Oct 17, 2022

After the latest update the ninja cursor is showing below the system cursor. I'm using the css snippet to recreate the iAwriter like cursor.

Screenshot_2022-10-17_18-40-56

@vrtmrz
Copy link
Owner

vrtmrz commented Oct 19, 2022

@ronrdev

So sorry for missing replies!

Also would it be possible to have different settings/css for light and dark mode?

Yes, we can! We can make different styles between both modes. as below:

/* The cursor colour in a light theme */
.theme-light .x-cursor {
    background: #00bbff;
}
/*The cursor colour in a dark theme */
.theme-dark .x-cursor {
    background: #ffbbff;
}

Just only make the scope narrow.

After the latest update the ninja cursor is showing below the system cursor. I'm using the css snippet to recreate the iAwriter like cursor.

Owing to the v1.0 upgrade, we have to ignore the area where tabs are shown, otherwise we could not move the window. So we have to offset the cursor also in custom CSS.
Just as like below:

    top: calc( -6px - var(--header-height));

Could you please try this CSS again?

@ronrdev
Copy link
Author

ronrdev commented Oct 19, 2022

Thank you for sharing the css. It's working great and ninja cursor feels more responsive with the new release.

@PootieeTang
Copy link

Hello and thank you for suggesting these features @ronrdev, additionally because you're a fan of iA Writer you should check out the plugin called Stille as it focuses on the sentence you're struggling. But I do have a question for @vrtmrz, is there anyway you can help me with this issue? I am noot sure if its a css problem or something I need to disable on my end. Basically the IA cursor you provided above works great for me, but it slightly is a bit faster than the original cursor, when the IA cursor blinks you can faintly see the system cursor.

Obsidian_83PezILgIl.mp4

@vrtmrz
Copy link
Owner

vrtmrz commented Feb 15, 2023

Oh my dear, I am really sorry for missing this!

If you feel noisy with the default cursor, we can make that invisible with this CSS:

.cm-editor * {
    caret-color: transparent !important;
}

@Anutim
Copy link

Anutim commented Mar 22, 2023

Oh my dear, I am really sorry for missing this!

If you feel noisy with the default cursor, we can make that invisible with this CSS:

.cm-editor * {
    caret-color: transparent !important;
}

Hey, this doesn't work when you have text selected. Any way to apply this for that too?

Also, the styling posted earlier in the thread (#3 (comment)) doesn't play nice with selected text in general, especially when there's multiple rows selected. You got any ideas on how to fix that? (Or alternatively, disabling the custom cursor while text is selected)

EDIT: Another thing I thought I'd ask too, I'm using 'transition-duration: 100ms;' to smoothen the movement of the caret.
It works great when I'm typing, but it's terrible for when I'm scrolling. Is there a way I could make it snappy again just for scrolling, but otherwise use the smooth transition-duration?

EDIT2: There also seems to be a bug where every 2nd scroll downwards or so, the cursors position doesn't update?

@dmalyuta
Copy link

@Anutim for hiding the cursor that appears when text is selected, I found that you can add:

.cm-cursorLayer {
    animation: none !important;
    visibility: hidden !important;
}

@Stakker
Copy link

Stakker commented May 24, 2023

Hello and thanks for making this excellent plugin :-)

I am also using it to have an iA Writer-style big and fat cursor that is easy to locate. (The "ninja swoosh" is a really cool idea that also serves a purpose, but perhaps a bit too wild for my taste :-)

Mostly this works great with the above snippets (thanks for sharing them!), but there are still two issues:

  1. The cursor reacts correctly to headers moving to the right to show the "#" and other dynamic WYSIWYG elements of the Live Preview mode, when I move to cursor over them using the keyboard. If I move the cursor to (for example) a header using the mouse, the cursor doesn't react to the text jumping to the right. I need to move it using the keyboard for it to catch up with the text.

  2. The smoothly fading opacity animation in the above snippet looks great, but uses three times more CPU than the normal CodeMirror cursor… It's a bit crazy IMO for just a cursor, so I disabled the animation completely. With the CodeMirror cursor hidden and no animation, Ninja Cursor uses three times LESS CPU than the default cursor, which is pretty awesome! However, I'm wondering if just blinking the cursor on/off would also be a CPU friendly option… But I don't know how to do that, or if it is even possible?

Cheers!

@Stakker
Copy link

Stakker commented May 25, 2023

A third issue: select multiple lines of text, and you can see a cursor for every line on the left. This is fine by me, but when I delete all the lines, the cursors on the left stay there until I move the cursor again.

There's also a minor issue when you fold/unfold a section. The cursor won't move until I let go of the modifier key. But this is not a biggie :-)

PS: I do understand that this is a bit of a hack, so not everything can be fixed… but hopefully some things can :-)

@ronrdev
Copy link
Author

ronrdev commented Jun 30, 2023

Hello

I had set an animation delay that is not working after updating today. I'm still looking for a solution. Not sure what changed that is affecting this.

/* Blinking */
.cursorWrapper .x-cursor0,
.cursorWrapper .x-cursor1 {
    animation: blink1 1s 0s both infinite;
    animation-delay: 2s;
}

@bramblebrain
Copy link

cursor-preview

Here’s my updated snippet that incorporates all the fixes as well as solves the latest bug with the cursor blinking during typing as well as the cursor sometimes not blinking when idle. In the code I did reduce the animation delay to 1 second.

/* iAWriter-ish style. */
.cursorWrapper .x-cursor {
    background: rgba(49, 177, 235, 1);
    width: 3px;
    left: -1px;
    top: calc( -6px - var(--header-height));;
    height: calc(12px + var(--cursor-height));
    transition: opacity;
}
/* The cursor colour in a light theme */
.theme-light .x-cursor {
    background: rgba(49, 177, 235, 1);
}
/*The cursor colour in a dark theme */
.theme-dark .x-cursor {
    /* replace if you want purple cursor
	background: rgba(225,187, 225, 1); */
	background: rgba(49, 177, 235, 1);
}

/* remove normal cursor when ninjacursor is installed.
Alternative method: caret-color: rgba(0, 0, 0, 1);
*/
body:has(.x-cursor) .cm-editor * {
caret-color: transparent;
}

/* Disable movement effect */
.cursorWrapper .x-cursor::after {
    display: none;
}

/* Remove normal cursor on text selection */
.cm-cursorLayer {
    animation: none !important;
    visibility: hidden !important;
}

/* Blinking */
.cursorWrapper .x-cursor0 {
	animation: blink0 1s 1s both infinite;
}
.cursorWrapper .x-cursor1 {
    animation: blink1 1s 1s both infinite;
}

@keyframes blink1 {
    0%   { opacity: 1;   }
    45%  { opacity: 1;   }
    50%  { opacity: 0.3; }
    95%  { opacity: 0;   }
    100% { opacity: 0.3; }
}

@keyframes blink0 {
    0%   { opacity: 1;   }
    45%  { opacity: 1;   }
    50%  { opacity: 0.3; }
    95%  { opacity: 0;   }
    100% { opacity: 0.3; }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants