Skip to content

Commit

Permalink
fix: 馃悰 slash plugin position error when editor size is small
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Apr 15, 2022
1 parent fd841bc commit d022991
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 102 deletions.
8 changes: 4 additions & 4 deletions examples/react/package.json
Expand Up @@ -7,10 +7,10 @@
"start": "vite"
},
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
"@types/react": "^17.0.6",
"@types/react-dom": "^17.0.5",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@milkdown/core": "workspace:*",
"@milkdown/preset-commonmark": "workspace:*",
"@milkdown/plugin-tooltip": "workspace:*",
Expand Down
2 changes: 2 additions & 0 deletions examples/vanilla/main.ts
Expand Up @@ -3,6 +3,7 @@ import './style.css';

import { defaultValueCtx, Editor, themeManagerCtx } from '@milkdown/core';
import { math } from '@milkdown/plugin-math';
import { slash } from '@milkdown/plugin-slash';
import { commonmark } from '@milkdown/preset-commonmark';
import { nord } from '@milkdown/theme-nord';
import { tokyo } from '@milkdown/theme-tokyo';
Expand All @@ -20,6 +21,7 @@ async function main() {
.use(tokyo)
.use(commonmark)
.use(math)
.use(slash())
.create();

await sleep(2000);
Expand Down
3 changes: 2 additions & 1 deletion examples/vanilla/package.json
Expand Up @@ -11,6 +11,7 @@
"@milkdown/preset-commonmark": "workspace:*",
"@milkdown/theme-nord": "workspace:*",
"@milkdown/theme-tokyo": "workspace:*",
"@milkdown/plugin-math": "workspace:*"
"@milkdown/plugin-math": "workspace:*",
"@milkdown/plugin-slash": "workspace:*"
}
}
13 changes: 11 additions & 2 deletions gh-pages/style.css
Expand Up @@ -54,6 +54,13 @@ body {
width: 100%;
}
transition: all 0.4s ease-in-out;

.editor {
@media only screen and (min-width: 72rem) {
max-width: 57.375em;
padding: 3.125em 7.25em !important;
}
}
}

.loading {
Expand All @@ -67,8 +74,10 @@ body {
max-width: 72rem !important;

.milkdown {
overflow: auto;
height: calc(100vh - 11.5rem - 20px);
.editor {
overflow: auto;
height: calc(100vh - 11.5rem - 110px);
}
}

position: relative;
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-slash/src/prose-plugin/view.ts
Expand Up @@ -29,7 +29,10 @@ const calculatePosition = (view: EditorView, dropdownElement: HTMLElement) => {
}

if (parent.height + parent.top - selected.bottom < target.height) {
top = selected.top - parent.top - target.height - 14 + $editor.scrollTop;
const topOffset = selected.top - parent.top - target.height - 14 + $editor.scrollTop;
if (topOffset > 0) {
top = topOffset;
}
}
return [top, left];
});
Expand Down
5 changes: 0 additions & 5 deletions packages/theme-nord/src/style.ts
Expand Up @@ -38,11 +38,6 @@ export const getStyle = (manager: ThemeManager, emotion: Emotion) => {
& > * {
margin: 1.875em 0;
}
@media only screen and (min-width: 72rem) {
max-width: 57.375em;
padding: 3.125em 7.25em;
}
`;

const paragraph = css`
Expand Down
5 changes: 0 additions & 5 deletions packages/theme-tokyo/src/style.ts
Expand Up @@ -38,11 +38,6 @@ export const getStyle = (manager: ThemeManager, emotion: Emotion) => {
& > * {
margin: 1.875em 0;
}
@media only screen and (min-width: 72rem) {
max-width: 57.375em;
padding: 3.125em 7.25em;
}
`;

const paragraph = css`
Expand Down

0 comments on commit d022991

Please sign in to comment.