Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

chore(editor): revert padding and layout of code block toolbar (#9562)

L-Sun6e0468c70ab0
diff --git a/blocksuite/affine/block-code/src/code-block.ts b/blocksuite/affine/block-code/src/code-block.ts
index 6f9d0adb34..9a178a698a 100644
--- a/blocksuite/affine/block-code/src/code-block.ts
+++ b/blocksuite/affine/block-code/src/code-block.ts
@@ -16,7 +16,7 @@ import {
getInlineRangeProvider,
TextSelection,
} from '@blocksuite/block-std';
-import { IS_MAC } from '@blocksuite/global/env';
+import { IS_MAC, IS_MOBILE } from '@blocksuite/global/env';
import { noop } from '@blocksuite/global/utils';
import {
INLINE_ROOT_ATTR,
@@ -389,6 +389,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent<
<div
class=${classMap({
'affine-code-block-container': true,
+ mobile: IS_MOBILE,
wrap: this.model.wrap,
})}
>
diff --git a/blocksuite/affine/block-code/src/code-toolbar/components/code-toolbar.ts b/blocksuite/affine/block-code/src/code-toolbar/components/code-toolbar.ts
index 1cd61c277a..5966ec699e 100644
--- a/blocksuite/affine/block-code/src/code-toolbar/components/code-toolbar.ts
+++ b/blocksuite/affine/block-code/src/code-toolbar/components/code-toolbar.ts
@@ -17,15 +17,19 @@ export class AffineCodeToolbar extends WithDisposable(LitElement) {
static override styles = css`
:host {
position: absolute;
+ width: 100%;
top: 0;
- right: 0;
+ left: 0;
}
.code-toolbar-container {
+ width: auto;
height: 24px;
gap: 4px;
padding: 4px;
margin: 0;
+ display: flex;
+ justify-content: flex-end;
}
.code-toolbar-button {
diff --git a/blocksuite/affine/block-code/src/code-toolbar/components/lang-button.ts b/blocksuite/affine/block-code/src/code-toolbar/components/lang-button.ts
index eb2c1841c8..09315fd200 100644
--- a/blocksuite/affine/block-code/src/code-toolbar/components/lang-button.ts
+++ b/blocksuite/affine/block-code/src/code-toolbar/components/lang-button.ts
@@ -17,6 +17,10 @@ export class LanguageListButton extends WithDisposable(
SignalWatcher(LitElement)
) {
static override styles = css`
+ :host {
+ margin-right: auto;
+ }
+
.lang-button {
background-color: var(--affine-background-primary-color);
box-shadow: var(--affine-shadow-1);
diff --git a/blocksuite/affine/block-code/src/code-toolbar/index.ts b/blocksuite/affine/block-code/src/code-toolbar/index.ts
index 140af99286..f5d08669f2 100644
--- a/blocksuite/affine/block-code/src/code-toolbar/index.ts
+++ b/blocksuite/affine/block-code/src/code-toolbar/index.ts
@@ -14,7 +14,7 @@ import {
TextSelection,
WidgetComponent,
} from '@blocksuite/block-std';
-import { limitShift, shift } from '@floating-ui/dom';
+import { limitShift, shift, size } from '@floating-ui/dom';
import { html } from 'lit';
import type { CodeBlockComponent } from '../code-block.js';
@@ -82,8 +82,13 @@ export class AffineCodeToolbarWidget extends WidgetComponent<
},
computePosition: {
referenceElement: codeBlock,
- placement: 'right-start',
+ placement: 'top',
middleware: [
+ size({
+ apply({ rects, elements }) {
+ elements.floating.style.width = `${rects.reference.width}px`;
+ },
+ }),
shift({
crossAxis: true,
padding: {
diff --git a/blocksuite/affine/block-code/src/styles.ts b/blocksuite/affine/block-code/src/styles.ts
index 5fd5955b63..1df5579ed8 100644
--- a/blocksuite/affine/block-code/src/styles.ts
+++ b/blocksuite/affine/block-code/src/styles.ts
@@ -9,12 +9,16 @@ export const codeBlockStyles = css`
font-size: var(--affine-font-xs);
line-height: var(--affine-line-height);
position: relative;
- padding: 12px;
+ padding: 28px 24px;
background: var(--affine-background-code-block);
border-radius: 10px;
box-sizing: border-box;
}
+ .affine-code-block-container.mobile {
+ padding: 12px;
+ }
+
.affine-code-block-container .inline-editor {
font-family: var(--affine-font-code-family);
font-variant-ligatures: none;