gpt4 book ai didi

visual-studio-code - 在 VSCode 中展开单个方法

转载 作者:行者123 更新时间:2023-12-05 04:48:46 31 4
gpt4 key购买 nike

VS Code 中是否有任何键盘快捷键允许我们展开单个方法并保持其他方法折叠?

我可以折叠和展开所有的方法,但是还没有找到一种方法来展开一个单一的方法

如果能够做到这一点,它将让我专注于单一方法,而不是被那些长长的代码行分心

例如下面...展开 getTitle 方法并保持其他操作折叠

import Web3 from "web3";

import Play from "../abis/Play.json";

export const WEB3_LOADED = "WEB3_LOADED";
export const WEB3_ACCOUNT_LOADED = "WEB3_ACCOUNT_LOADED";
export const TOKEN_LOADED = "TOKEN_LOADED";
export const PLAY_LOADED = "PLAY_LOADED";
export const GET_NAME = "GET_NAME";
export const SET_NAME = "SET_NAME";
export const CHANGE_TEST = "CHANGE_TEST";
export const LOAD_ALL_DATA = "LOAD_ALL_DATA";
export const TRANSFER_LOADING = "TRANSFER_LOADING";
export const TRANSFER_LOADED = "TRANSFER_LOADED";

export const loadWeb3 = (eth) => {
const web3 = new Web3(eth);
return async (dispatch) => {
dispatch({
type: WEB3_LOADED,
connection: web3,
});
return web3;
};
};

export const loadAccount = (web3) => {
return async (dispatch) => {
const accounts = await web3.eth.getAccounts();
const account = accounts[0];
dispatch({
type: WEB3_ACCOUNT_LOADED,
account,
});
};
};

export const loadPlay = (web3, networkId) => {
return async (dispatch) => {
try {
const play = new web3.eth.Contract(
Play.abi,
Play.networks[networkId].address
);
dispatch({
type: PLAY_LOADED,
play,
});
return play;
} catch (error) {
console.log("Play Contract Not Deployed");
return null;
}
};
};

export const getName = () => {
return async (dispatch, getState) => {
const name = await getState().play.play.methods.name().call();
dispatch({
type: GET_NAME,
name,
});
};
};

export const setName = (name) => {
return async (dispatch, getState) => {
try {
const { account } = getState().web3;
const { play } = getState().play;
play.methods
.setName(name)
.send({
from: account,
})
.on("transactionHash", (hash) => {
dispatch({
type: SET_NAME,
name,
});
})
.on("error", (error) => {
console.error(error);
window.alert("There was an error setting Name");
});
} catch (error) {
window.alert("Failed to Set Name");
}
};
};

export const loadAllData = () => {
return async (dispatch, getState) => {
const { play } = getState().play;
const transferStream = await play.getPastEvents("Transfer", {
fromBlock: 0,
toBlock: "latest",
});
const allTransferred = transferStream.map((event) => event.returnValues);
dispatch({
type: LOAD_ALL_DATA,
allTransferred,
});
};
};

export const subscribeToEvents = () => {
return async (dispatch, getState) => {
const { play } = getState().play;
play.events.Transfer({}, (error, event) => {
dispatch({
type: TRANSFER_LOADED,
payload: event.returnValues,
});
});
};
};

export const transfer = (amount) => {
return async (dispatch, getState) => {
const { account } = getState().web3;
const { play } = getState().play;
await play.methods
.transfer(amount)
.send({
from: account,
})
.on("transactionHash", () => {
dispatch({
type: TRANSFER_LOADING,
});
})
.on("error", (error) => {
console.error(error);
window.alert("There was an error Transferring");
});
};
};

export const getTitle = () => {
return async (dispatch, getState) => {
const title = await getState().play.play.methods.title().call();
console.log(title);
};
};

export const testDemo = () => {
return async (dispatch, getState) => {
console.log(dispatch, getState());
};
};

export const changeTest = () => {
return {
type: CHANGE_TEST,
name: "ali",
};
};

最佳答案

Ctrl+Shift+[ 折叠一个区域,而Ctrl+Shift+] 展开一个区域,如 Key Bindings Documentation 中所述:

Folding

您还需要确保光标位于正确的位置。

如果你想递归折叠/展开,你可以使用Ctrl + K, Ctrl + < kbd>[ 折叠,Ctrl + K, Ctrl + ] 展开。这将折叠/展开区域内的所有区域(即 getTitle() 函数,它的 return 函数将分别折叠/展开)。

关于visual-studio-code - 在 VSCode 中展开单个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67913279/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com